From: Marco Antoniotti
Subject: Scheme idiom or Scheme extension?
Date: 
Message-ID: <CW%5c.105$IJ5.80720@typhoon.nyu.edu>
Hi

I was going through Sussman's "Structure and Implementation of Classical 
Mechanics" (http://www-swiss.ai.mit.edu/~gjs/6946/sicm-html/index.html) 
and came upon the following idiom:

(define ((L-free-particle mass) local)
   (let ((v (velocity local)))
     (* 1/2 mass (dot-product v v))))

AFAIK this ain't R^nRS.  What is the semantics of the above?  I tried to 
look around nearby links, but then I decided it'd be easier just to ask.

Cheers

marco

From: Barry Margolin
Subject: Re: Scheme idiom or Scheme extension?
Date: 
Message-ID: <barmar-9F4C92.13001717032004@comcast.ash.giganews.com>
In article <···················@typhoon.nyu.edu>,
 Marco Antoniotti <·······@cs.nyu.edu> wrote:

> Hi
> 
> I was going through Sussman's "Structure and Implementation of Classical 
> Mechanics" (http://www-swiss.ai.mit.edu/~gjs/6946/sicm-html/index.html) 
> and came upon the following idiom:
> 
> (define ((L-free-particle mass) local)
>    (let ((v (velocity local)))
>      (* 1/2 mass (dot-product v v))))
> 
> AFAIK this ain't R^nRS.  What is the semantics of the above?  I tried to 
> look around nearby links, but then I decided it'd be easier just to ask.

It's an extension.  Just as

(define (<identifier> <args>) <body>)

is equivalent to

(define <identifer> (lambda (args) <body>))

So then

(define ((<identifier> <args1>) <args2>) <body>)

is equivalent to

(define (<identifier> <args1>)
  (lambda (<args2>) <body>))

which is equivalent to

(define <identifier>
  (lambda (<args1>) (lambda (<args2>) <body>)))

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Joe Marshall
Subject: Re: Scheme idiom or Scheme extension?
Date: 
Message-ID: <d67bxmuu.fsf@ccs.neu.edu>
Marco Antoniotti <·······@cs.nyu.edu> writes:

> Hi
>
> I was going through Sussman's "Structure and Implementation of
> Classical Mechanics"
> (http://www-swiss.ai.mit.edu/~gjs/6946/sicm-html/index.html) and came
> upon the following idiom:
>
> (define ((L-free-particle mass) local)
>    (let ((v (velocity local)))
>      (* 1/2 mass (dot-product v v))))
>
> AFAIK this ain't R^nRS.  What is the semantics of the above?  I tried
> to look around nearby links, but then I decided it'd be easier just to
> ask.

If you want to hack this, you need the scmutils package.  It is
*heavily* modified from standard scheme:  case-sensitive identifiers,
symbolic math integrated with regular math, etc.
From: Marco Antoniotti
Subject: Re: Scheme idiom or Scheme extension?
Date: 
Message-ID: <8Cj6c.108$IJ5.83075@typhoon.nyu.edu>
Joe Marshall wrote:

> Marco Antoniotti <·······@cs.nyu.edu> writes:
> 
> 
>>Hi
>>
>>I was going through Sussman's "Structure and Implementation of
>>Classical Mechanics"
>>(http://www-swiss.ai.mit.edu/~gjs/6946/sicm-html/index.html) and came
>>upon the following idiom:
>>
>>(define ((L-free-particle mass) local)
>>   (let ((v (velocity local)))
>>     (* 1/2 mass (dot-product v v))))
>>
>>AFAIK this ain't R^nRS.  What is the semantics of the above?  I tried
>>to look around nearby links, but then I decided it'd be easier just to
>>ask.
> 
> 
> If you want to hack this, you need the scmutils package.  It is
> *heavily* modified from standard scheme:  case-sensitive identifiers,
> symbolic math integrated with regular math, etc.

Thanks to all who answered.  I had a hunch it was for something along 
these lines.

I will look into scmutils too.

Cheers
--
marco
From: Anton van Straaten
Subject: Re: Scheme idiom or Scheme extension?
Date: 
Message-ID: <3l06c.6949$CJ5.3760@newsread2.news.atl.earthlink.net>
Marco Antoniotti wrote:
> Hi
>
> I was going through Sussman's "Structure and Implementation of Classical
> Mechanics" (http://www-swiss.ai.mit.edu/~gjs/6946/sicm-html/index.html)
> and came upon the following idiom:
>
> (define ((L-free-particle mass) local)
>    (let ((v (velocity local)))
>      (* 1/2 mass (dot-product v v))))
>
> AFAIK this ain't R^nRS.  What is the semantics of the above?  I tried to
> look around nearby links, but then I decided it'd be easier just to ask.

You're right, it's not RnRS.  It's an extension supported by MIT Scheme, for
defining curried functions, so this:

  (define ((L-free-particle mass) local) ...)

translates to this:

(define L-free-particle
  (lambda (mass)
    (lambda (local)
      ...)

This makes it easy to do things like, in this case, defining a function
representing a particle with a particular mass:

(define heavy-particle (L-free-particle 10000))

and later apply that function with (heavy-particle foo).

Note that the form of the definition corresponds to the usage form, e.g.:

((L-free-particle 10000) foo)

In a Lisp-2, this would involve a FUNCALL:

(funcall (L-free-particle 10000) foo)

Anton
From: Ivan Boldyrev
Subject: Re: Scheme idiom or Scheme extension?
Date: 
Message-ID: <9guni1xne3.ln2@ibhome.cgitftp.uiggm.nsc.ru>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 8686 day of my life Anton van Straaten wrote:
> Marco Antoniotti wrote:
>> Hi
>>
>> I was going through Sussman's "Structure and Implementation of Classical
>> Mechanics" (http://www-swiss.ai.mit.edu/~gjs/6946/sicm-html/index.html)
>> and came upon the following idiom:
>>
>> (define ((L-free-particle mass) local)
>>    (let ((v (velocity local)))
>>      (* 1/2 mass (dot-product v v))))
>>
>> AFAIK this ain't R^nRS.  What is the semantics of the above?  I tried to
>> look around nearby links, but then I decided it'd be easier just to ask.
>
> You're right, it's not RnRS.  It's an extension supported by MIT Scheme, for
> defining curried functions.

...

> In a Lisp-2, this would involve a FUNCALL:
>
> (funcall (L-free-particle 10000) foo)

Or use DEFCURRIED:

(defun curry-wrapper (function arguments-number &optional known-arguments)
  (declare (type function function)
           (type fixnum arguments-number)
           (type list known-arguments))
  #'(lambda (&rest new-arguments)
      (let ((tail (nthcdr (1- arguments-number) new-arguments)))
        (cond
          ((null tail)  ; If (length new-arguments) < arguments-number
           (curry-wrapper function
                          (- arguments-number (length new-arguments))
                          (append known-arguments new-arguments)))
           ((null (rest tail)) ; if arguments-number = (length new-arguments)
            (apply function (append known-arguments new-arguments)))
           (t
            (apply  ; function returns other function that will consume rest
             (apply function
                    (append known-arguments
                            (subseq new-arguments 0 arguments-number)))
             (rest tail)))))))

(defmacro defcurried (function-name args &body body)
  "Define function function-name with simple arglist args and body as
curried function.  Body may contain a docstring."
  (let* ((doc-string
          (if (and (stringp (car body))
                   (not (null (rest body))))
              (list (car body))
              nil))
         (real-body (if doc-string (rest body) body))
         (arguments (gensym (symbol-name function-name))))
    `(defun ,function-name (&rest ,arguments)
      ,@doc-string
      (apply
       (curry-wrapper #'(lambda ,args ,@real-body) ,(length args))
       ,arguments))))


- -- 
Ivan Boldyrev

Violets are red, Roses are blue. //
I'm schizophrenic, And so am I.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.3.5 (GNU/Linux)

iQEVAwUBQFlK6A4ALcwzZFpVAQI3Zwf7BbRz5ORaG/VTtxzYO2CevyAhjLWb+LkP
UV/xo95O+xP/u/wSMzTxrkoJLy95b1OsXipqGpJf3x8mMgDOcoLXvlac48JnP/Uc
i1kSGrnevGNeD87UoS56vLrWwR+WgtRQgvaIsURi1Sruc2ZlbD95EbEbqxN80WKT
o1rm/Fx3mrUkYFy+muemj18xR3uFLWQvtGf1sJ77kTjj/QoQYTPFFf6IoUn6c3mo
x15mfOjPa1vhnXv3MmygYmMRQ09UcqiZ5D67EVNnDs8J4iv5nMnf//ZvE8Vev+3p
rty8DvJO/X7QITitUVgFsAWeLRjs4mpweOZNUGkV9+tZlXkcWHci7A==
=3Ick
-----END PGP SIGNATURE-----
From: Neelakantan Krishnaswami
Subject: Re: Scheme idiom or Scheme extension?
Date: 
Message-ID: <slrnc5i5rv.2gs.neelk@gs3106.sp.cs.cmu.edu>
In article <···················@typhoon.nyu.edu>, Marco Antoniotti wrote:
> 
> I was going through Sussman's "Structure and Implementation of Classical 
> Mechanics" (http://www-swiss.ai.mit.edu/~gjs/6946/sicm-html/index.html) 
> and came upon the following idiom:
> 
> (define ((L-free-particle mass) local)
>    (let ((v (velocity local)))
>      (* 1/2 mass (dot-product v v))))
> 
> AFAIK this ain't R^nRS.  What is the semantics of the above?  I
> tried to look around nearby links, but then I decided it'd be easier
> just to ask.

IIRC, this is an extension to make writing curried functions more
convenient. Ie,

  (define ((foo x) y) expression)

means the same thing as

  (define foo
     (lambda (x)
        (lambda (y) expression)))

I haven't had a chance to read SICM yet, though it's been on my shelf
for a while. I envy you. :)

-- 
Neel Krishnaswami
·····@cs.cmu.edu