Re: The LOOP macro
From: Edi Weitz (edi_at_agharta.de)
Date: 03/25/04
- Next message: Joe Marshall: "Re: The LOOP macro"
- Previous message: Daniel C. Wang: "Re: Postdoc position in program development, analysis and transformation"
- In reply to: André Thieme: "Re: The LOOP macro"
- Next in thread: Joe Marshall: "Re: The LOOP macro"
- Reply: Joe Marshall: "Re: The LOOP macro"
- Reply: André Thieme: "Re: The LOOP macro"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 25 Mar 2004 02:06:02 +0100
On Wed, 24 Mar 2004 23:59:39 +0100, André Thieme <this.address.is.good.until.2004.apr.17@justmail.de> wrote:
> But to be fair, when a language X does not support a feature the
> users of X can always say that you can simply implement this
> feature. In the same time the users of language Y think: oh, we
> already have this and this looks like an advantage. So when we can
> say: "Ok, Lisp cannot do it but we can always program it in a way so
> it gets this feature", then we can also use the same argument for
> another language which does not directly support a feature which
> Lisp supports.
No, generally you can't. You are comparing apples to oranges.
Granted, we are all Lisp zealots and we think that all other languages
are junk but take a look at this nevertheless:
1. IIRC, some (all?) Schemes have an extension to COND where you can
write '=>' after a test form such that if the test form evaluates
to a true value the function behind the '=>' is applied to the
result of the test form. You want that in Common Lisp? Wait...
* (defmacro cond* (&rest conditions)
(let ((=var= (gensym)))
`(let (,=var=)
(cond
,@(loop for condition in conditions
when (and (symbolp (second condition))
(string= (symbol-name (second condition))
"=>"))
collect (list `(setq ,=var= ,(first condition))
`(funcall ,(third condition) ,=var=))
else
collect condition)))))
COND*
* (defun foo (x)
(cond* ((eq 3 4) "Really?")
(x => (lambda (z) (format nil "Yes, ~A is it!" z)))
(t "Nothing found")))
FOO
* (foo nil)
"Nothing found"
* (foo 42)
"Yes, 42 is it!"
2. Your code is full of dates and you'd really like to have a shortcut
like !2001-11-09 instead of
(ENCODE-UNIVERSAL-TIME 0 0 0 9 11 2001)
Well, ok...
* (defun date-reader (stream char)
(declare (ignore char))
(let ((exp (read stream t nil t)))
(when (symbolp exp)
(let ((y-m-d (nth-value 1
(cl-ppcre:scan-to-strings "^(\\d{4})-(\\d{2})-(\\d{2})"
(symbol-name exp)))))
(return-from date-reader
(apply #'encode-universal-time 0 0 0
(nreverse (map 'list #'parse-integer y-m-d))))))
(error "Ooops...")))
DATE-READER
* (set-macro-character #\! #'date-reader)
T
* !2004-03-25
3289158000
* (decode-universal-time *)
0
0
0
25
3
2004
3
NIL
-1
(Of course, these values are inserted into your code at read time,
not at run time.)
So, OK, these are silly and probably buggy examples but I hope you get
the idea: Can you add new control structures to Java and Python or
change their read syntax without mucking with the
compiler/interpreter? Compared to most other languages Lisp is almost
infinitely extendable.
Edi.
- Next message: Joe Marshall: "Re: The LOOP macro"
- Previous message: Daniel C. Wang: "Re: Postdoc position in program development, analysis and transformation"
- In reply to: André Thieme: "Re: The LOOP macro"
- Next in thread: Joe Marshall: "Re: The LOOP macro"
- Reply: Joe Marshall: "Re: The LOOP macro"
- Reply: André Thieme: "Re: The LOOP macro"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|