Discussion:
Aliasing functions?
(too old to reply)
Axel Reichert
2020-05-20 21:44:41 UTC
Permalink
Hello,

assume you find some Scheme code on the web but are too lazy to
translate it manually into Common Lisp. Are there any "compatibility
packages" that allow you to use

(define (foo bar)
baz)

instead of

(defun foo (bar)
baz)

? This one should be a trivial macro, but how about the other major
differences, "foo?" instead of "foop" or "foo-bar?" instead of
"foo-bar-p", "setf" versus "set!", "t" instead of "else" in "cond" and
so on?

I am fully aware that a full automatism is probably not feasible.

Best regards

Axel

P. S.: Does anyone know about the motivation/history behind the
different bracketing of "define" and "defun" above?
--
-X- | in memoriam John Conway
--X | 1937-2020
XXX | A glider from his "Game of Life"
t***@google.com
2020-05-21 01:05:25 UTC
Permalink
Post by Axel Reichert
P. S.: Does anyone know about the motivation/history behind the
different bracketing of "define" and "defun" above?
DEFUN came well before DEFINE
I've seen this answered on this group before.
I'm trying to recall some of the details.

IIRC one reason for the difference was that initially there was no special syntax for defining
a named function. Instead, one just associated a LAMBDA expression with a symbol. This
was, I believe, done by using the appropriate function tag on a symbol's plist (property
list). At some point DEFUN appeared as a macro to simplify this a little bit by wrapping
up the original code which used PUTPROP (not in CL) to associate the function tag
with a lambda expression.

So, the symbol that would be bound to the function was distinguished in a way that
today would likely not be done. But backwards compatibility kept DEFUN and so there
was not great need in CL for a generalized DEFINE. It was also the case, that one could
define different kinds of function-like objects using additional values like FEXPR.

It would be fairly easy for you to write a DEFINE macro that could be used to define
say just functions and global dynamic variables. I recall you wanted to look into that.
So this would be a fairly simple, though non-trivial macro to write.
Helmut Eller
2020-05-21 06:43:22 UTC
Permalink
Post by t***@google.com
Post by Axel Reichert
P. S.: Does anyone know about the motivation/history behind the
different bracketing of "define" and "defun" above?
DEFUN came well before DEFINE
I've seen this answered on this group before.
I'm trying to recall some of the details.
IIRC one reason for the difference was that initially there was no
special syntax for defining
a named function. Instead, one just associated a LAMBDA expression with a symbol. This
was, I believe, done by using the appropriate function tag on a symbol's plist (property
list).
But the "pseudo function" to do that was called DEFINE, right? The LISP
1.5 manual has a DEFINE function but no DEFUN. So I think DEFINE came
before DEFUN, though it had a different syntax than Scheme's define.

Helmut
t***@google.com
2020-05-26 22:36:32 UTC
Permalink
Post by Helmut Eller
Post by t***@google.com
DEFUN came well before DEFINE
...
But the "pseudo function" to do that was called DEFINE, right? The LISP
1.5 manual has a DEFINE function but no DEFUN. So I think DEFINE came
before DEFUN, though it had a different syntax than Scheme's define.
Ah, yes, correct.
I never worked with Lisp 1.5, but it did have DEFINE but not DEFUN.
MacLisp had DEFUN (or DEFPROP or PUTPROP) but not DEFINE.

Kaz Kylheku
2020-05-21 01:49:38 UTC
Permalink
Post by Axel Reichert
P. S.: Does anyone know about the motivation/history behind the
different bracketing of "define" and "defun" above?
Note that Scheme, being a Lisp-1, originally just had this:

(define symbol (lambda (...) ...))

This syntax is still there in Scheme, of course: it's just
the syntax for defining a variable.

The (define (function arg ...)) syntax got overloaded onto this
using the same define symbol.

It more or less has to have the variation in list structure to
disambiguate the two variants, or at least to do so in what is probably
the simplest way with the fewest parsing hacks.

Note that (define function (arg)) looks indistinguishable from
the function being defined to have the value of evaluating the
(arg) expression. We could have some hacky rule like that the
body must not be empty:

(define function (arg) something-here)

but that's annoying, possibly error prone, and possibly interferes
future docstring support (or possibly current docstring support
in some Scheme implementations that have it as an extension)

That is to say, if something-here is a string

(define function (arg) "blah")

that could in some implementations be taken as a docstring for the
variable foo whose value is obtained by evaluating (arg), which prevents
us from using this syntax to write a function which returns a literal
string.

So then we need a rule like:

(define function (arg) [ optional-docstring ] something-here)

It starts to get messy and ugly, compared to the alternative
which was selected, which requires define to just look at whether
its argument is a list or an atom.

Also, Scheme is inspired by the C (for instance, just look at the
unspecified order of argument evaluation, and undefined return value
of side-effecting procedures). So this can be regarded as an expression
of admiration for C's "declaration follows use" syntax design principle.
--
TXR Programming Lanuage: http://nongnu.org/txr
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1
Axel Reichert
2020-05-21 10:45:00 UTC
Permalink
Post by Kaz Kylheku
(define symbol (lambda (...) ...))
This syntax is still there in Scheme
I have to admit that I do have some sympathies for consistently using

(define foo "bar")

and

(define baz (lambda (quux) (* 2 quux)))

instead of

(define (baz quux) (* 2 quux))

It kind of stresses the Lisp-1 character.
Post by Kaz Kylheku
It more or less has to have the variation in list structure to
disambiguate the two variants [...]
Great explanations, thanks!

Axel
--
-X- | in memoriam John Conway
--X | 1937-2020
XXX | A glider from his "Game of Life"
Loading...