Page 1 of 1
Vacuum-tube Lisp
Posted: Sun May 25, 2008 2:35 pm
by m i c h a e l
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
Posted: Sun May 25, 2008 4:30 pm
by Lutz
I also enjoyed the post, but want to add this to make the resulting functions a bit faster.
Instead of:
Code: Select all
(define (car x) (first x))
(define (cdr x) (rest x))
just do:
Code: Select all
(define car first)
(define cdr rest)
or if you want to have them protected against change and global:
Code: Select all
(constant (global 'car) first)
(constant (global 'crd) rest)
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::
Code: Select all
(constant (global 'then) begin)
(constant (global 'else) begin)
; now you can do
(if condition
(then ...)
(else ...)
)
Posted: Sun May 25, 2008 6:25 pm
by xytroxon
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 ...)
)
LOL... That's exactly what I have been using!
(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 ...)
)
Then I delete out the then- and else- after I have it working...
But still, this style:
Code: Select all
(if condition
(begin ...)
(begin ...)
)
just looks to me like my code is "stuttering"...
And the ideal Lisp compressed form?
Code: Select all
(if condition (begin ...)(begin ...))
It is so, hanging chad, 72 column Hollerith punch card looking to me...
(And we all know what problems hanging chads on Hollerith punch cards can be ;)
-- xytroxon
Posted: Sun May 25, 2008 6:59 pm
by Kazimir Majorinc
I do not like "begin", because I wander why there is no "end". But I didn't replaced it yet.
But I happily replaced "lambda" with "function" and "lambda-macro" with "macro".
Posted: Sun May 25, 2008 7:39 pm
by Lutz
'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.
Posted: Sun May 25, 2008 8:59 pm
by cormullion
thanks m i c h a e l ! Just feeling whimsical this weekend. :)
Posted: Sun May 25, 2008 9:32 pm
by Kazimir Majorinc
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.
This is how I did it.
(set 'macro (lambda-macro()(eval (append '(lambda-macro) (args)))))
(set 'function (
macro()(eval (append '(lambda) (args)))))
It works.
Posted: Mon May 26, 2008 1:10 am
by Lutz
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