3 ms·
If you have Quicklisp[1] installed you can install the "infix" package and get infix notation in Common Lisp[2]: $ sbcl This is SBCL 1.2.4.debian, an i
by rol 11y ago
If you have Quicklisp[1] installed you can install the "infix" package and get infix notation in Common Lisp[2]:
$ sbcl
This is SBCL 1.2.4.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
> (ql:quickload 'infix)
; Loading package
(INFIX)
> #i(1 + 1) ; addition
2
> #i(2^^128) ; exponentiation
340282366920938463463374607431768211456
> (defun factorial (x)
#i(if x == 0 then
1
else
x * factorial(x-1))) ; infix function call
FACTORIAL
> (factorial 5)
120
> #i(factorial(5) / factorial(6))
1/6
> '#i((a + b) * (c + d)) ; Put a ' before the #i() to see what code is generated
(* (+ A B)
(+ C D))
--
[1] - https://www.quicklisp.org/beta/ https://www.quicklisp.org/beta/
[2] - Don't know if there is a similar package for Scheme.
- adwf 11y agoI wouldn't recommend using infix libraries if you really want to get into Common Lisp though. They're a bit of a crutch for people coming from other languages, but that's it. Pretty much the whole language is based on Polish notation. The sooner you realise that + - * / are just function names like any other, the better you'll do. For example: (+ 1 2 3) in plain symbols is just: (function parameter parameter parameter) But if I were to write my own addition function: (addition 1 2 3) it would also be: (function parameter parameter parameter) and so is: (http-request "http://www.google.com") (function parameter) If you use infix notation, you're writing half your code in a competely different semantic to the other half. I can't imagine it helping people really get a proper grasp of how Common Lisp works.
- jrapdx3 11y ago> Don't know if there is a similar package for Scheme. I have to agree with others in the thread that infix in Lisp/Scheme is not the convention, and IMO an awkward fit. Don't recall encountering infix in any published/shared code I've seen, it may exist, but to learn Scheme becoming comfortable with s-expr notation is definitely necessary. However, there is SRFI 105[0] which describes "curly infix expressions". It's implemented in Guile 2.x, possibly available in a few others but evidently not had a lot of uptake among Schemes. [0] http://srfi.schemers.org/srfi-105/srfi-105.html http://srfi.schemers.org/srfi-105/srfi-105.html Edit: added URL