I have really liked Ruby for the very reason that I can often
express algorithms from scheme/lisp directly in Ruby, but with a much
more readable syntax. Yes, This will be controversial to the lambda
devotees. However, my point is that Ruby can do this far easier than
languages like C or Java.
The ‘endless discussion’ does seem to be a feature of learning to
program in Lisp. I suppose this may be because people who program in
Lisp give a lot of thought to details of both design and
implementation of software. However, I suspect that it may be that
Lisp attracts a certain amount of what we used to call ‘rules lawyers’
at the gaming table.
I have really liked Ruby for the very reason that I can often
express algorithms from scheme/lisp directly in Ruby, but with a much
more readable syntax. Yes, This will be controversial to the lambda
devotees. However, my point is that Ruby can do this far easier than
languages like C or Java.
I agree that Ruby syntax is usually nicer.
However, it’s a lot more difficult to play with macros if you have
Ruby-like syntax.
S-expressions make it much easier
On Thu, Jul 27, 2006 at 06:48:31AM +0900, N Okia wrote:
The ‘endless discussion’ does seem to be a feature of learning to
program in Lisp. I suppose this may be because people who program in
Lisp give a lot of thought to details of both design and
implementation of software. However, I suspect that it may be that
Lisp attracts a certain amount of what we used to call ‘rules lawyers’
at the gaming table.
While you may not want “rules lawyers” and “min-maxers” in your RPG
sessions, which are largely social events, there are some significant
advantages to be gained from such means of considering programming
problems. I’d rather have a “rules lawyer” writing my code than someone
who, conversely, doesn’t think the rules matter.
the nearest lambda (or equivalent) by default, just like in Ruby.
That’s why one uses LET for local variables.
Can we macro around it or something, so that
(set-local-variable variable value) introduces a function-local variable
without increasing indentation level each time it’s being done?
I think it’s reasonable to write something like that (whatever the names
of set-local-variable operator is):
Such a macro would be a strange beast indeed. The problem is that
indentation level actually reflects lexical scope, which means that
set-local-variable would have to find the environment for the function
veclen and change this after it was defined. What you could do if the
nesting is bad for you is to introduce CL’s aux variables:
(defun veclen (x y &aux (x2 (* x x)) (y2 (* y y)) (z2 (+ x2 y2)))
(sqrt z2))
This is of course just syntactic sugar, but it works and is
standardized. I recommend you do this, keep setf/setq for changing the
variables, but leave let alone.
(There may also be a way to override the standard meaning of “defun”
to have it do what your “defun-with-local” macro does, but I’d
recommend strongly against overriding standard parts of the language
like that)
You would have to do a code-walker (with all the glory such a thing
brings), find all places where you have local and more or less replace
them with let and let* each time you find one.
Actually, you could even shorten that slightly to:
(defun-with-local pythag (x y)
(local x2 (* x x) y2 (* y y))
(local z2 (+ x2 y2))
(sqrt z2))
But I think that hurts the readability.
Note that you don’t need to supply an initial value in the (local)
bit. Also, a (local) declaration will shadow references that follow
it, but not those that precede it. For example:
(defvar a 'top)
A
a
TOP
(progn-with-local (setf a 'before) (local a) (setf a 'after))
AFTER