Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

λ notation

8 views
Skip to first unread message

John Thingstad

unread,
Feb 20, 2008, 1:20:01 AM2/20/08
to
I was messing around in LispWorks the other day and came up with this
lambda notation.
(mapcar λ(e) (+ e 10) '(1 2 3 4)

(I guess Kenny is right. I was supposed to be working on my BugTrack
program, but this was more fun..)
Warning: This contains LispWorks spesific code.

;;-*-mode: lisp; coding: utf-16;-*-

;; lambda notation using λ
;; Written: February 2008 John Thingstad ©
;;
;; use: (mapcar λ(e) (+ e 10) '(1 2 3 4)
;; (mapcar λ(a b) (+ a b)
;; (loop repeat 10 collect (random 10))
;; (loop for i from 0 upto 10 collect i))
;;
;; To enter λ type Control-Alt-l
;;
;; To use this in the editor you need a font that supports unicode
;; like "Lucida Console".

;; simple-char supports unicode unlike default base-char

(set-default-character-element-type 'simple-char)

;; reader: λ gets expanded to (lambda (read) (read))

(defun lambda-reader (stream char)
(declare (ignore char))
(list 'lambda
(read stream nil (values) t)
(read stream nil (values) t)))

(set-macro-character #\λ #'lambda-reader)

;; editor: control-l inserts λ in lisp mode

(editor:defcommand "Insert Lambda" (p)
(declare (ignore p))
(editor:insert-character (editor:current-point) #\λ))

(editor:bind-key "Insert Lambda" #\meta-\control-\l :mode "lisp")


--------------
John Thingstad

levy

unread,
Feb 20, 2008, 4:01:04 AM2/20/08
to
Here are some of my ideas:

;; this is a simple macro
(mapcar (λ (α) (+ α 10)) '(1 2 3 4))

;; this can be done with a reader macro
(mapcar Λ(+ α 10) '(1 2 3 4)) ;; greek characters are implicit
arguments in alphabetical order

;; this can also be done with a macro
(mapcar (« + 10) '(1 2 3 4)) ;; where '«' is like curry

;; this kind of compose implicitly takes function names as arguments
;; probably needs to be done after read and before compile by
processing the contents recursively
;; CL is not flexible enough to be able to implement easily such
syntax extensions
(find element list :key (a ° b ° c))

;; these are easy
(≠ 1 2)
(≤ 1 3)
(√ 16)
(Σ '(1 2 3 4))
(Π '(1 2 3 4))

;; recursive calls
(defun gcd (a b)
(if (= b 0)
a
(if (< a b)
(↻ b a)
(↻ b (mod a b)))))

and many more...

To type in a greek character one can either type 'lambda' and let
emacs replace it by 'λ' or bind it to a key such as C-l with an
appropriate prefix. It is also possible to type in 'lambda' and let
emacs display it as 'λ' even though the file contains the word
'lambda'. The other special characters could be handled similarily.

And as soon as we forget about storing and editing the code as simple
text files this whole notation issue becomes a matter of taste/
preference per user per session per whatever you want...

levy

Mirko....@gmail.com

unread,
Feb 20, 2008, 7:23:13 AM2/20/08
to

No, no, no.

The only reason why I am programming in fortran and lisp in UPPERCASE
is because I yearn for the good old days.

But seriously, I like the idea very much, except, that the one thing I
like more are, ahem, portability. Would this fly across platforms and
IDE's?

Mirko

Alex Mizrahi

unread,
Feb 20, 2008, 7:57:21 AM2/20/08
to
l> ;; CL is not flexible enough to be able to implement easily such
l> syntax extensions
l> (find element list :key (a œ b œ c))

if you really prefer (a œ b œ c) to (œ a b c), and even (œ a œ b œ c) won't
satisfy you, than perhaps it would be better for you to use some other
programming language.. Fortress?


John Thingstad

unread,
Feb 20, 2008, 8:09:39 AM2/20/08
to
På Wed, 20 Feb 2008 13:57:21 +0100, skrev Alex Mizrahi
<udod...@users.sourceforge.net>:

Unicode is not a rare thing in CL...

--------------
John Thingstad

Pascal J. Bourguignon

unread,
Feb 20, 2008, 9:19:16 AM2/20/08
to
Mirko....@gmail.com writes:

Of course. What matters is not what is in the file, or what you type,
but what is displayed.

When I type (SIGMA '(1 2 3 4)) in my lisp buffers in emacs, it
displays as (Σ '(1 2 3 4)), as part of font-locking, and I'm happy,
but it saves to files as (SIGMA '(1 2 3 4)) and my co-workers are happy,
and my lazy friend can type Alt-S-s, bound to (lambda () (interactive)
(insert "SIGMA")) and be happy too.

It more or less defeats the purpose of Unicode,
but that maintains backward compatibility.


--
__Pascal Bourguignon__

Joost Diepenmaat

unread,
Feb 20, 2008, 9:27:44 AM2/20/08
to
p...@informatimago.com (Pascal J. Bourguignon) writes:

> Of course. What matters is not what is in the file, or what you type,
> but what is displayed.
>
> When I type (SIGMA '(1 2 3 4)) in my lisp buffers in emacs, it
> displays as (Σ '(1 2 3 4)), as part of font-locking, and I'm happy,
> but it saves to files as (SIGMA '(1 2 3 4)) and my co-workers are happy,
> and my lazy friend can type Alt-S-s, bound to (lambda () (interactive)
> (insert "SIGMA")) and be happy too.

This sounds pretty cool. Can you give me a hint how to configure that?
I have a hard time coming up with a good "apropos" word for this
functionality...

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Pascal J. Bourguignon

unread,
Feb 20, 2008, 11:28:11 AM2/20/08
to

Have a look at: http://darcs.informatimago.com/emacs/pjb-sources.el
search for greek-letter-font-lock and pretty-greek.

--
__Pascal Bourguignon__
mailto:pascal.bo...@anevia.com
http://www.anevia.com

Raymond Wiker

unread,
Feb 20, 2008, 12:50:53 PM2/20/08
to
"John Thingstad" <jpt...@online.no> writes:

Unicode *does not exist* in CL, but it may be available in
certain CL implementations...

John Thingstad

unread,
Feb 20, 2008, 1:12:20 PM2/20/08
to

... implementations.
In fact it is available in nearly all.
(Read the code and comments)

--------------
John Thingstad

Joost Diepenmaat

unread,
Feb 20, 2008, 3:09:20 PM2/20/08
to
p...@anevia.com (Pascal J. Bourguignon) writes:

> Have a look at: http://darcs.informatimago.com/emacs/pjb-sources.el
> search for greek-letter-font-lock and pretty-greek.

Thanks!

levy

unread,
Feb 21, 2008, 11:51:35 AM2/21/08
to
On febr. 20, 13:57, "Alex Mizrahi" <udode...@users.sourceforge.net>
wrote:

> l> ;; CL is not flexible enough to be able to implement easily such
> l> syntax extensions
> l> (find element list :key (a OE b OE c))
>
> if you really prefer (a OE b OE c) to (OE a b c), and even (OE a OE b OE c) won't

> satisfy you, than perhaps it would be better for you to use some other
> programming language.. Fortress?

What a constructive comment, down with mathematics and notations
invented there...

levy

Alex Mizrahi

unread,
Feb 22, 2008, 6:05:31 AM2/22/08
to
l>>> ;; CL is not flexible enough to be able to implement easily such
l>>> syntax extensions
l>>> (find element list :key (a ½ b ½ c))
??>>
??>> if you really prefer (a ½ b ½ c) to (½ a b c), and even (½ a ½ b ½ c)
??>> won't satisfy you, than perhaps it would be better for you to use some
??>> other programming language.. Fortress?
??>>
JT> Unicode is not a rare thing in CL...

it's not about unicode, it's about using infix notation instead of prefix.
levy complained that CL is not flexible enough to be able to support infix


John Thingstad

unread,
Feb 22, 2008, 7:08:05 AM2/22/08
to
På Fri, 22 Feb 2008 12:05:31 +0100, skrev Alex Mizrahi
<udod...@users.sourceforge.net>:

> l>>> ;; CL is not flexible enough to be able to implement easily such

Guess he was wrong..

--------------
John Thingstad

Kent M Pitman

unread,
Feb 22, 2008, 8:09:25 AM2/22/08
to
"Alex Mizrahi" <udod...@users.sourceforge.net> writes:

IMO, the latter claim is simply false.

Is one permitted to say that Java or C is not capable of adding 2 and
2, since it has no built-in AddTwoAndTwo() operation, or is someone
claiming lack of capability/flexibility obliged to consider that some
things will be possible and the language is flexible enough to
accommodate them without actually requiring the language to
pre-implement them?

The default CL parser is a reader, not an algebraic parser. But it's
under user control and you could change that. A great deal of its
design is intended to accommodate such needs.

Nothing other than mere lack of interest has kept CL programmers from
doing in CL what Vaughan Pratt did in MACLISP when he wrote CGOL. All
of the relevant capabilities are there.

If you want the capability, you can write it. The language designers
provided you a core that was "flexible enough".

Is Fortress "flexible enough" to do the reverse, supporting Lisp notation?

If not, which is the more notationally flexible?

Leslie P. Polzer

unread,
Feb 22, 2008, 8:35:55 AM2/22/08
to

Does anyone know whether there's something prepackaged for Vim that
does such stuff?

John Thingstad

unread,
Feb 23, 2008, 12:51:14 AM2/23/08
to
På Fri, 22 Feb 2008 14:09:25 +0100, skrev Kent M Pitman
<pit...@nhplace.com>:

I don't think it is lack of ability as much as lack of documentation which
is the problem. This exercise was just a attempt to clearify the power of
reader macros. The idea was to introduce a chapter in the CL cookbook
(probably without the Unicode). But I need to understand it myself first.

--------------
John Thingstad

levy

unread,
Feb 24, 2008, 4:27:21 PM2/24/08
to
If you quote me then please quote precisely, I hate politics where
people shuffle and filter words at will!

As I said: 'CL is not flexible enough to be able to implement easily
such
syntax extensions' where _easily_ is key I think.

levy

Leslie P. Polzer

unread,
Feb 29, 2008, 12:29:27 PM2/29/08
to
On 22 Feb, 14:35, "Leslie P. Polzer" <leslie.pol...@gmx.net> wrote:
> Does anyone know whether there's something prepackaged for Vim that
> does such stuff?

Ah, I guess the conceal patch does just that.

Leslie

0 new messages