Vacuum-tube Lisp

For the Compleat Fan
Locked
m i c h a e l
Posts: 394
Joined: Wed Apr 26, 2006 3:37 am
Location: Oregon, USA
Contact:

Vacuum-tube Lisp

Post 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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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 ...)
)

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Post 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
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post 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".

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

thanks m i c h a e l ! Just feeling whimsical this weekend. :)

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post 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.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Locked