[plt-scheme] apply vs dot notation syntax

From: Jos Koot (jos.koot at telefonica.net)
Date: Sun Oct 5 07:55:32 EDT 2008

I think we would have a problem when writing (f a b . (g c d)).
This always should mean the same thing as (f a b g c d).
Although PLT scheme makes it possible to discern
(f a b . (g c d)) from (f a b g c d), when read as syntax, it seems 
undesirable to make this distinction, I think. It certainly is going to 
cause problems in code that relies on the equivalence of (a . (b)) and (a 
b), for instance in the expansion of non primitive syntaxes. The distinction 
can be made as follows:

Language Pretty Big:

(module my-app scheme
 (define-syntax (my-app stx)
  (define (head-and-tail e)
   (let loop ((e e) (h '()))
    (cond
     ((null? e) (values (reverse h) (syntax '( ))))
     ((pair? e) (loop (cdr e) (cons (car e) h)))
     (else (values (reverse h) e)))))
  (syntax-case stx ()
   ((_ . x)
    (let-values (((head tail) (head-and-tail (syntax-e #'x))))
   #`(#%app apply #, at head #,tail)))))
 (provide (rename-out (my-app #%app))))

(require 'my-app)
(define x (list 1 2 3))
(define (f c) (+ c . x))
(f 4) ; --> 10
(define (g c) (+ c . (list 1 2 3)))
(g 4) ; --> 10

Jos

----- Original Message ----- 
From: <kbohdan at mail.ru>
To: <plt-scheme at list.cs.brown.edu>
Sent: Sunday, October 05, 2008 12:35 PM
Subject: [plt-scheme] apply vs dot notation syntax


> Hi all,
>
> Probably it was discussed ages ago but could not find any links
> regarding the following question.
> Why scheme has 'apply' primitive instead of simple dot
> notation ? i.e. we can use
>
> (f arg1 arg2 . rest-of-args-list)
>
> instead of standard:
>
> (apply f arg1 arg2 rest-of-args-list)
>
> The former looks similar to the 'define' syntax
> and has advantage to be processed by a compiler
> in some special way. For example, optimizer can remove
> some unused arguments. Doing the same optimization with
> standard approach looks unnatural from the compiler design
> perspective : compiler [lower layer] should know about function primitives 
> [higher level].
>
> Thanks.
>
> --
> Bohdan
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 



Posted on the users mailing list.