Vacuum-tube Lisp
-
- Posts: 394
- Joined: Wed Apr 26, 2006 3:37 am
- Location: Oregon, USA
- Contact:
Vacuum-tube Lisp
cormullion,
Loved your last post at unbalanced-parentheses: "Vacuum-tube Lisp." I really appreciated the quote from "Slug" in light of the recent car/cdr thread.
Inspired by a chapter in a now-forgotten book, I once intended to write a song about the cddr/cadadr permutations. Someday, maybe I'll get around to doing it :-)
Also, your joke about giving up writing because of us Hollywood types made me realize something: videos can cover subjects only superficially, while writing can explore those subjects in true depth. It's like the difference between movies and novels. Maybe one day, we'll witness someone writing the following blog entry, "The newLISP Introduction movie was okay, but it really didn't do cormullion's original justice" ;-)
m i c h a e l
Loved your last post at unbalanced-parentheses: "Vacuum-tube Lisp." I really appreciated the quote from "Slug" in light of the recent car/cdr thread.
Inspired by a chapter in a now-forgotten book, I once intended to write a song about the cddr/cadadr permutations. Someday, maybe I'll get around to doing it :-)
Also, your joke about giving up writing because of us Hollywood types made me realize something: videos can cover subjects only superficially, while writing can explore those subjects in true depth. It's like the difference between movies and novels. Maybe one day, we'll witness someone writing the following blog entry, "The newLISP Introduction movie was okay, but it really didn't do cormullion's original justice" ;-)
m i c h a e l
I also enjoyed the post, but want to add this to make the resulting functions a bit faster.
Instead of:
just do:
or if you want to have them protected against change and global:
The new 'car' and 'cdr' now will behave just like the originals and with same speed.
While we at it, lets do something for a friendlier 'if' suggested in this group earlier::
Instead of:
Code: Select all
(define (car x) (first x))
(define (cdr x) (rest x))
Code: Select all
(define car first)
(define cdr rest)
Code: Select all
(constant (global 'car) first)
(constant (global 'crd) rest)
While we at it, lets do something for a friendlier 'if' suggested in this group earlier::
Code: Select all
(constant (global 'then) begin)
(constant (global 'else) begin)
; now you can do
(if condition
(then ...)
(else ...)
)
LOL... That's exactly what I have been using!Lutz wrote: While we at it, lets do something for a friendlier 'if' suggested in this group earlier::
Code: Select all
(constant (global 'then) begin) (constant (global 'else) begin) ; now you can do (if condition (then ...) (else ...) )
(After the "passionate" responses, I was kind of afraid to ask if that was the fastest form ;)
The above style is helpful while editing and creating code and helps me to quickly regain my focus in subsquent editing sessions... Even days later...
But I have started using this style, to ease my "Lisp-think" transition...
Code: Select all
(if condition
(then-begin ...)
(else-begin ...)
)
But still, this style:
Code: Select all
(if condition
(begin ...)
(begin ...)
)
And the ideal Lisp compressed form?
Code: Select all
(if condition (begin ...)(begin ...))
(And we all know what problems hanging chads on Hollerith punch cards can be ;)
-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976
-- Let's Talk Lisp (c) 1976
-
- Posts: 388
- Joined: Thu May 08, 2008 1:24 am
- Location: Croatia
- Contact:
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
-
- Posts: 388
- Joined: Thu May 08, 2008 1:24 am
- Location: Croatia
- Contact:
This is how I did it.Lutz wrote:'lambda' and 'lambda-macro are the only reserved word, which cannot be replaced, but you can use 'fn' and 'fn-macro' instead, which are also built in.
(set 'macro (lambda-macro()(eval (append '(lambda-macro) (args)))))
(set 'function (macro()(eval (append '(lambda) (args)))))
It works.
Nice solution! You even can take out the 'eval' and the quotes, because in newLISP lambda expressions evaluate to themselves ;-)
Code: Select all
(set 'macro (lambda-macro() (append (lambda-macro) (args))))
(set 'function (macro() (append (lambda) (args))))
(set 'foo (macro (x y) (+ (eval x) (eval y))))
(foo 3 4) => 7
(set 'foo (function (x y) (+ x y)))
(foo 4 5) => 9