From: Bill Birch
Subject: (setq car 0) - Functions on Indices
Date: 
Message-ID: <6f7fa60c.0210012324.57e1a382@posting.google.com>
Hi All,

Paul Graham's web site (www.paulgraham.com) has a neat idea regarding
compounds in Arc.  e.g.
   ("helo" 2) ==> \l

   (a 5) ; instead of Common Lisp (aref a 5)


My own dialect of Lisp now has something similar. Integers are allowed
as special functions! So in RefLisp the following are legal:

   (0 '(one two)) ==> one  

   (2 '(one two three)) ==> three


What's more, after I made this change nothing broke, all my old Lisp
code still runs! I only modified APPLY to call NTH when the function
is an integer. Which means it would probably work in any other Lisp
too.

I found some other advantages, you can use integer variables as
accessors. for example:
    (setq real 0) (setq imaginary 1)
    (setq complex '(2.3 4.5))

    (real complex)  => 2.30000

here's some code from a Lisp tutorial:

  (defun cabbage-side (state) (nth 3 state)) 
 
which becomes

  (setq cabbage-side 3)

You can define NTH as:

   (defun nth (n exp) (n exp))
    
And finally CAR is redefined as:

   (setq car 0)

And yes, this actually works!

There is no reason why this could not be also made to work for strings
and arrays:

   (2 "helo") ==> \l

   (5 a) ; instead of Common Lisp (aref a 5)

Your views?
What about negative numbers?
      perhaps starting from the end of the list:
       (-1 '(q w e r t y)) ==> y

Regards,
Bill Birch
 b i r c h b @ o z e m a i l . c o m . a u

From: Matthew Danish
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <20021002041213.L10389@lain.res.cmu.edu>
On Wed, Oct 02, 2002 at 12:24:13AM -0700, Bill Birch wrote:
> Paul Graham's web site (www.paulgraham.com) has a neat idea regarding
> compounds in Arc.  e.g.
>    ("helo" 2) ==> \l
> 
>    (a 5) ; instead of Common Lisp (aref a 5)

This is a piece of syntactic sugar, and while some people may prefer the
shorthand, I myself do not have any problems with `(aref a 5)'.

> 
> My own dialect of Lisp now has something similar. Integers are allowed
> as special functions! So in RefLisp the following are legal:
> 
>    (0 '(one two)) ==> one  
> 
>    (2 '(one two three)) ==> three

(first '(one two)) ==> one
(third '(one two three)) => three

> 
> 
> What's more, after I made this change nothing broke, all my old Lisp
> code still runs! I only modified APPLY to call NTH when the function
> is an integer. Which means it would probably work in any other Lisp
> too.

Besides the fact that most any compiler would likely need a great deal
of modification in order to permit integers as functions (type-analysis,
transforms, various function call mechanisms), consider that a Lisp-2
would be looking at the function-cell of a value.

> 
> I found some other advantages, you can use integer variables as
> accessors. for example:
>     (setq real 0) (setq imaginary 1)
>     (setq complex '(2.3 4.5))
> 
>     (real complex)  => 2.30000

This is the sort of thing which should be avoided.  Usage of a struct
(or in this case, the CL built-in complex type) would be more informative
and efficient.

Keep in mind, what you did is essentially the same as
(defun real (x) (first x))

> 
> here's some code from a Lisp tutorial:
> 
>   (defun cabbage-side (state) (nth 3 state)) 
>  
> which becomes
> 
>   (setq cabbage-side 3)

Not in any modern Lisp.  Where did you declare cabbage-side?  Not to
mention how a Lisp-2 would behave.

> 
> You can define NTH as:
> 
>    (defun nth (n exp) (n exp))
>     
> And finally CAR is redefined as:
> 
>    (setq car 0)
> 
> And yes, this actually works!

Then you have an awfully strange Lisp, since `aref' stands for `array
reference', last time I checked.

> Your views?

I see little gained, possible confusion added, and harder to optimize
code resulting.

If you desperately need a shorthand for AREF, consider this (or similar):

(set-syntax-from-char #\] #\))
(set-macro-character #\[ #'(lambda (stream char) 
			     (cons 'aref 
				   (read-delimited-list #\] stream))))

(let ((a #(1 2 3)))
  [a 1])

-- 
; Matthew Danish <·······@andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."
From: Marco Antoniotti
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <y6cr8f8r7d3.fsf@octagon.valis.nyu.edu>
Matthew Danish <·······@andrew.cmu.edu> writes:

> On Wed, Oct 02, 2002 at 12:24:13AM -0700, Bill Birch wrote:
> > Paul Graham's web site (www.paulgraham.com) has a neat idea regarding
> > compounds in Arc.  e.g.
> >    ("helo" 2) ==> \l
> > 
> >    (a 5) ; instead of Common Lisp (aref a 5)
> 
> This is a piece of syntactic sugar, and while some people may prefer the
> shorthand, I myself do not have any problems with `(aref a 5)'.

Not to mention that it is relatively easy to write a generalized REF
function/macro that masks all the possible indexing that could be done
in CL.

Cheers


-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
715 Broadway 10th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.
From: Jeremy Yallop
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <ane828$dg9vd$1@ID-114079.news.dfncis.de>
Bill Birch wrote:
> What's more, after I made this change nothing broke, all my old Lisp
> code still runs! I only modified APPLY to call NTH when the function
> is an integer. Which means it would probably work in any other Lisp
> too.

What happens to the following?

  (setq foo 0)
  (defun foo (x) x)
  (foo '(1 2 3))

Jeremy.
From: Dorai Sitaram
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <anetvk$cst$1@news.gte.com>
In article <··············@ID-114079.news.dfncis.de>,
Jeremy Yallop  <······@jdyallop.freeserve.co.uk> wrote:
>Bill Birch wrote:
>> What's more, after I made this change nothing broke, all my old Lisp
>> code still runs! I only modified APPLY to call NTH when the function
>> is an integer. Which means it would probably work in any other Lisp
>> too.
>
>What happens to the following?
>
>  (setq foo 0)
>  (defun foo (x) x)
>  (foo '(1 2 3))

Arc is a Lisp1, so the above situation is not
ambiguous. 
From: Christopher C. Stacy
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <ulm5h9tcu.fsf@dtpq.com>
>>>>> On 2 Oct 2002 00:24:13 -0700, Bill Birch ("Bill") writes:
 Bill> Your views?

Just because something is an interesting idea to play with doesn't
imply that meets people's various criteria of what constitutes a 
good programming language.  There is a complex balance of power,
readability, conciseness, and how the language constructs will
all come together and allow programmers to combine them into
the kinds of programs that they want to write.  There can be 
different ways of achieving this, such as APL or LISP, but it
surely doesn't come from throwing together random elements.

Defining the integers to name accessor functions must surely 
have ramifications beyond what you have written about so far.
What are they?
From: Kaz Kylheku
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <cf333042.0210020657.262845d0@posting.google.com>
······@ozemail.com.au (Bill Birch) wrote in message news:<····························@posting.google.com>...
> Hi All,
> 
> Paul Graham's web site (www.paulgraham.com) has a neat idea regarding
> compounds in Arc.  e.g.
>    ("helo" 2) ==> \l
> 
>    (a 5) ; instead of Common Lisp (aref a 5)

That's a stupidity. What do you do when you want (a 5) to call the
function a with argument 5?
 
> My own dialect of Lisp now has something similar. Integers are allowed
> as special functions! So in RefLisp the following are legal:
> 
>    (0 '(one two)) ==> one  
> 
>    (2 '(one two three)) ==> three
> 
> What's more, after I made this change nothing broke, all my old Lisp
> code still runs!

Of course, why wouldn't it? You turned an error situation into defined
behavior. So only bizarre programs break; those which trigger the
error on purpose and trap it as part of their control flow logic.


> I only modified APPLY to call NTH when the function
> is an integer. Which means it would probably work in any other Lisp
> too.

But what about:

  (defun foo (...)...)

  (let ((foo 0))
    (foo array))

Should foo be evaluated to an integer? Or treated as a function name?
What is called?

If you only allow integer constants to be function names, well, heck,
you can already do that, or nearly that, in standard Lisp:

  (defmacro |1| (&rest args) `(aref 1 ,@args))
  (defmacro |2| ( ...      ) `(aref 2 ...   ))
   ...

:)

> I found some other advantages, you can use integer variables as
> accessors. for example:
>     (setq real 0) (setq imaginary 1)
>     (setq complex '(2.3 4.5))
> 
>     (real complex)  => 2.30000

Allowing a variable definition to shadow a function is a good thing?
What exactly are the evaluation rules for (real ...)? To work this as
a conforming extension in Common Lisp, the rules would have to be
something like: if the main connective is a lexical or dynamic
variable bound to an integer value, then treat it as a function. If it
a symbol with a function binding, treat it as a function also. 
Otherwise if it is an expression that designates a function, such a
lambda expression, treat it as a function call. Otherwise error.

> What about negative numbers?
>       perhaps starting from the end of the list:
>        (-1 '(q w e r t y)) ==> y

I think that if you really want this kind of silliness, you should
contain it in a mini language, which is firewalled from the rest of
the program by a macro call which establishes the scope in which that
language is understood.

  (in-funny-lisp-flavor
    (-1 '(q w e r t y)))
From: Tim Bradshaw
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <ey3smzou9sy.fsf@cley.com>
* Kaz Kylheku wrote:

> That's a stupidity. What do you do when you want (a 5) to call the
> function a with argument 5?

This is never ambiguous, is it?  If A is an array you do the aref
thing, if it's a function, call it.

I'm fairly sure it is nothing new, either.  Zetalisp (and maybe
maclisp before it) had funcallable arrays, and I think that calling an
array with numerical arguments was equivalent to aref.  I don't think
they had any kind of special magic evaluation rule for them (so, say
(let ((a (make-array ...))) (a 1 2)) would not work.  Obviously a
Lisp1 doesn't need a special rule.  I'm also not sure if my memory is
right - I never used it, but I remember noticing it in the Symbolics
Common Lisp manual as a nonconformity.
 
--tim
From: Paul Wallich
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <pw-E563AB.12390902102002@reader1.panix.com>
In article <···············@cley.com>, Tim Bradshaw <···@cley.com> 
wrote:

>* Kaz Kylheku wrote:
>
>> That's a stupidity. What do you do when you want (a 5) to call the
>> function a with argument 5?
>
>This is never ambiguous, is it?  If A is an array you do the aref
>thing, if it's a function, call it.

CL being a Lisp2, what if it's both? Say that you have a list of things 
that's kept in an array and somewhere you're foolish enough to refer to 
it as "list"? Obviously you'd have to be at least a little bit stupid to 
do that, but the problems associated with that kind of overloading are 
exactly why Lisp2's in the first place. Perhaps you could have some kind 
of check that would do the array call only if you supplied the right 
number of numeric arguments and satisfied a bounds check, and otherwise 
would call the function...

>I'm fairly sure it is nothing new, either.  Zetalisp (and maybe
>maclisp before it) had funcallable arrays, and I think that calling an
>array with numerical arguments was equivalent to aref.  I don't think
>they had any kind of special magic evaluation rule for them (so, say
>(let ((a (make-array ...))) (a 1 2)) would not work.  Obviously a
>Lisp1 doesn't need a special rule.  I'm also not sure if my memory is
>right - I never used it, but I remember noticing it in the Symbolics
>Common Lisp manual as a nonconformity.

If you really wanted to drive yourself crazy, you shouldn't limit this 
kind of behavior to arrays. Calling a list with a numeric arg would give 
you nth, calling a hash table with a key would  give you the match, 
calling a string with numeric arguments would give you a subsequence
and so forth.  Such a language would be much more compact and 
expressive, and would strike fear into the hearts of Lisp2 programmers 
everywhere.
From: Tim Bradshaw
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <ey3k7l0u6rc.fsf@cley.com>
* Paul Wallich wrote:

> CL being a Lisp2, what if it's both? Say that you have a list of
> things that's kept in an array and somewhere you're foolish enough
> to refer to it as "list"? Obviously you'd have to be at least a
> little bit stupid to do that, but the problems associated with that
> kind of overloading are exactly why Lisp2's in the first
> place. Perhaps you could have some kind of check that would do the
> array call only if you supplied the right number of numeric
> arguments and satisfied a bounds check, and otherwise would call the
> function...

I think I was thinking of something where the function value of
something was an array.  One would probably need a special operator to
set this up.  You could overload FLET in fact:

    (let ((x (make-array ...)))
      (flet ((x x))
        (x ...)))

But may be I was just not thinking, in fact.

> Such a language would be much more
> compact and expressive, and would strike fear into the hearts of
> Lisp2 programmers everywhere.

Not this one.

--tim
From: Justin Johnson
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <1033577726.90660.0@demeter.uk.clara.net>
> If you really wanted to drive yourself crazy, you shouldn't limit this
> kind of behavior to arrays. Calling a list with a numeric arg would give
> you nth, calling a hash table with a key would  give you the match,
> calling a string with numeric arguments would give you a subsequence
> and so forth.  Such a language would be much more compact and
> expressive, and would strike fear into the hearts of Lisp2 programmers
> everywhere.

('(one two three) :at 2)            => two
("hello" :at 2 )                         => "e"
("hello" :at 2 :len 3)                 => "ell"

Isn't this beginning to smell a little OOP like? ;-) (which, IMHO, is not a
bad thing...)

--
Justin Johnson
From: Paul Wallich
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <pw-A7DB6F.14544002102002@reader1.panix.com>
In article <··················@demeter.uk.clara.net>,
 "Justin Johnson" <·······@mobiusent.com> wrote:

>> If you really wanted to drive yourself crazy, you shouldn't limit this
>> kind of behavior to arrays. Calling a list with a numeric arg would give
>> you nth, calling a hash table with a key would  give you the match,
>> calling a string with numeric arguments would give you a subsequence
>> and so forth.  Such a language would be much more compact and
>> expressive, and would strike fear into the hearts of Lisp2 programmers
>> everywhere.
>
>('(one two three) :at 2)            => two
>("hello" :at 2 )                         => "e"
>("hello" :at 2 :len 3)                 => "ell"
>
>Isn't this beginning to smell a little OOP like? ;-) (which, IMHO, is not a
>bad thing...)

It's beginning to smell a lot like early versions of smalltalk, where 
you sent unevaluated messages to minimally evaluated receivers so that 
you were halfway through the dispatch-and-act process before you had any 
clue what was going on. That's when you go objects all the way down, so 
that 3 + 5 means "send a message to the object representing the 
(probably integer) number 5 telling it to do the right thing to 'add' 
something whose printed representation in the current context is 3 to 
itself." Among other things the question of figuring out where you are 
in the class hierarchy can get interesting, and compilation and 
execution may be less efficient than you would like.
From: Tim Bradshaw
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <ey3fzvou5u4.fsf@cley.com>
* Justin Johnson wrote:

> Isn't this beginning to smell a little OOP like? ;-) (which, IMHO,
> is not a bad thing...)

It's only looking OOP like if you consider OOP and subject-verb-object
order to be the same thing.  Lisp is a verb-subject-object (or
verb-arguments) language (like most programming languages - the
difference is that Lisp doesn't have so many special cases).

If you want SVO it's quite easy to write readmacro which provides it:

    [x aref 0 1 3] -> (aref x 0 1 3)

    [x car] -> (car x)

    [x describe]

and so on.
From: Dorai Sitaram
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <anfl6s$d61$1@news.gte.com>
In article <···············@cley.com>, Tim Bradshaw  <···@cley.com> wrote:
>* Justin Johnson wrote:
>
>> Isn't this beginning to smell a little OOP like? ;-) (which, IMHO,
>> is not a bad thing...)
>
>It's only looking OOP like if you consider OOP and subject-verb-object
>order to be the same thing.  Lisp is a verb-subject-object (or
>verb-arguments) language (like most programming languages - the
>difference is that Lisp doesn't have so many special cases).
>
>If you want SVO it's quite easy to write readmacro which provides it:
>
>    [x aref 0 1 3] -> (aref x 0 1 3)

The matter isn't so much about flipping S,V,O amongst
themselves as about dropping some of them as
redundant.  The lang designer notices that there is no
possible non-error interpretation for a non-procedural
value occurring at the head of an application, so he
might as well posit a natural-seeming non-error
interpretation for it.

[x aref 0 1 3] isn't any better than (aref x 0 1 3).
(x 0 1 3) is, not only because it dispenses with the
aref (the Verb) altogether, but because it reads
practically like the mathematical x[0,1,3].
From: Tim Bradshaw
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <ey31y78tu6p.fsf@cley.com>
* Dorai Sitaram wrote:

> The matter isn't so much about flipping S,V,O amongst
> themselves as about dropping some of them as
> redundant.  The lang designer notices that there is no
> possible non-error interpretation for a non-procedural
> value occurring at the head of an application, so he
> might as well posit a natural-seeming non-error
> interpretation for it.

So long as everyone can agree what is natural, I guess.
From: Dorai Sitaram
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <anhk3u$ekm$1@news.gte.com>
In article <···············@cley.com>, Tim Bradshaw  <···@cley.com> wrote:
>* Dorai Sitaram wrote:
>
>> The lang designer notices that there is no
>> possible non-error interpretation for a non-procedural
>> value occurring at the head of an application, so he
>> might as well posit a natural-seeming non-error
>> interpretation for it.
>
>So long as everyone can agree what is natural, I guess.

Well, I just said the designer picks a natural-seeming
interpretation knowing that there is a syntactic
opportunity.  

Look, I'm not praising the choice, nor am I
saying it is a universal and/or objectively determined
thing.  If the latter, I would have chosen words that
reek less of subjective preference that "might as
well", "posit", and "natural-seeming"!  :-)
From: Tim Bradshaw
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <ey3n0pvqxl3.fsf@cley.com>
* Dorai Sitaram wrote:

> Look, I'm not praising the choice, nor am I
> saying it is a universal and/or objectively determined
> thing.  If the latter, I would have chosen words that
> reek less of subjective preference that "might as
> well", "posit", and "natural-seeming"!  :-)

Yes, sorry, my `so long as everyone can ...' wasn't meant to mean
anything else but that it needs to be something people do agree on.
In the case of arrays it probably is a completely natural choice.

--tim
From: Barry Margolin
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <YjGm9.18$0w.2383@paloalto-snr1.gtei.net>
In article <···············@cley.com>, Tim Bradshaw  <···@cley.com> wrote:
>I'm fairly sure it is nothing new, either.  Zetalisp (and maybe
>maclisp before it) had funcallable arrays, and I think that calling an
>array with numerical arguments was equivalent to aref.

Maclisp had them, and Zetalisp had it just for Maclisp compatibility.

In Maclisp, arrays were often defined similarly to functions.  Rather than

(setq a (make-array '(3 4)))

I think you would do:

(array a 3 4)

This would put the array in A's property list (Maclisp didn't have function
cells -- all attributes other than the name and value were in the plist),
and then

(a i j)

would look in A's plist to see whether it was a function, fexpr, macro, or
array, and do the appropriate thing (if it had more than one of these
properties, my guess is that it used whichever was first in the plist).

Since there was no AREF function, I'm not sure how you accessed arrays that
were received as function parameters.  I think maybe it wasn't possible
(unless you turned on the option that enabled EVAL of the CAR of a
function-call expression), so arrays were not used as much in Maclisp as
they are now (this is why Maclisp also had hunks, which were 2^N-element
generalizations of conses -- they were used instead of arrays to implement
DEFSTRUCT).

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Justin Johnson
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <1033575900.88733.0@demeter.uk.clara.net>
> That's a stupidity. What do you do when you want (a 5) to call the
> function a with argument 5?

I disagree.  I think this is useful shorthand.

The original poster has developed his own dialect of Lisp which, if it is
anything like Arc, is a Lisp1.  Functions and vars do not use the same
symbol.

>   (defun foo (...)...)
>
>   (let ((foo 0))
>     (foo array))

I would expect this to use 'foo' of 0 because it is primarily visible in the
lexical scope of the let.

> I think that if you really want this kind of silliness, you should
> contain it in a mini language, which is firewalled from the rest of
> the program by a macro call which establishes the scope in which that
> language is understood.

You haven't raised _one_ convincing argument about why this is silly.

> > What about negative numbers?
> >       perhaps starting from the end of the list:
> >        (-1 '(q w e r t y)) ==> y

Neat.

IMHO, I think it looks a little strange and doesn't feel quite descriptive
enough.

--
Justin Johnson


"Kaz Kylheku" <···@ashi.footprints.net> wrote in message
·································@posting.google.com...
> ······@ozemail.com.au (Bill Birch) wrote in message
news:<····························@posting.google.com>...
> > Hi All,
> >
> > Paul Graham's web site (www.paulgraham.com) has a neat idea regarding
> > compounds in Arc.  e.g.
> >    ("helo" 2) ==> \l
> >
> >    (a 5) ; instead of Common Lisp (aref a 5)
>
> That's a stupidity. What do you do when you want (a 5) to call the
> function a with argument 5?
>
> > My own dialect of Lisp now has something similar. Integers are allowed
> > as special functions! So in RefLisp the following are legal:
> >
> >    (0 '(one two)) ==> one
> >
> >    (2 '(one two three)) ==> three
> >
> > What's more, after I made this change nothing broke, all my old Lisp
> > code still runs!
>
> Of course, why wouldn't it? You turned an error situation into defined
> behavior. So only bizarre programs break; those which trigger the
> error on purpose and trap it as part of their control flow logic.
>
>
> > I only modified APPLY to call NTH when the function
> > is an integer. Which means it would probably work in any other Lisp
> > too.
>
> But what about:
>
>   (defun foo (...)...)
>
>   (let ((foo 0))
>     (foo array))
>
> Should foo be evaluated to an integer? Or treated as a function name?
> What is called?
>
> If you only allow integer constants to be function names, well, heck,
> you can already do that, or nearly that, in standard Lisp:
>
>   (defmacro |1| (&rest args) `(aref 1 ,@args))
>   (defmacro |2| ( ...      ) `(aref 2 ...   ))
>    ...
>
> :)
>
> > I found some other advantages, you can use integer variables as
> > accessors. for example:
> >     (setq real 0) (setq imaginary 1)
> >     (setq complex '(2.3 4.5))
> >
> >     (real complex)  => 2.30000
>
> Allowing a variable definition to shadow a function is a good thing?
> What exactly are the evaluation rules for (real ...)? To work this as
> a conforming extension in Common Lisp, the rules would have to be
> something like: if the main connective is a lexical or dynamic
> variable bound to an integer value, then treat it as a function. If it
> a symbol with a function binding, treat it as a function also.
> Otherwise if it is an expression that designates a function, such a
> lambda expression, treat it as a function call. Otherwise error.
>
> > What about negative numbers?
> >       perhaps starting from the end of the list:
> >        (-1 '(q w e r t y)) ==> y
>
> I think that if you really want this kind of silliness, you should
> contain it in a mini language, which is firewalled from the rest of
> the program by a macro call which establishes the scope in which that
> language is understood.
>
>   (in-funny-lisp-flavor
>     (-1 '(q w e r t y)))
From: Bill Birch
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <6f7fa60c.0210021655.4bede90e@posting.google.com>
···@ashi.footprints.net (Kaz Kylheku) wrote in message news:<····························@posting.google.com>...
> ······@ozemail.com.au (Bill Birch) wrote in message news:<····························@posting.google.com>...
> > Hi All,
> > 
> > Paul Graham's web site (www.paulgraham.com) has a neat idea regarding
> > compounds in Arc.  e.g.
> >    ("helo" 2) ==> \l
> > 
> >    (a 5) ; instead of Common Lisp (aref a 5)
> 
> That's a stupidity. What do you do when you want (a 5) to call the
> function a with argument 5?
>  
> > My own dialect of Lisp now has something similar. Integers are allowed
> > as special functions! So in RefLisp the following are legal:
> > 
> >    (0 '(one two)) ==> one  
> > 
> >    (2 '(one two three)) ==> three
> > 
> > What's more, after I made this change nothing broke, all my old Lisp
> > code still runs!
> 
> Of course, why wouldn't it? You turned an error situation into defined
> behavior. So only bizarre programs break; those which trigger the
> error on purpose and trap it as part of their control flow logic.
> 
> 
> > I only modified APPLY to call NTH when the function
> > is an integer. Which means it would probably work in any other Lisp
> > too.
> 
> But what about:
> 
>   (defun foo (...)...)
> 
>   (let ((foo 0))
>     (foo array))
> 
OK, here's what happens:

(progn
  (setq array '(1 2 3))
  (defun foo (x) "return a string")

  (let ((foo 0))
    (foo array)))

evaluates to ==> 1
From: Barry Margolin
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <T0Em9.5$0w.762@paloalto-snr1.gtei.net>
In article <····························@posting.google.com>,
Bill Birch <······@ozemail.com.au> wrote:
>You can define NTH as:
>
>   (defun nth (n exp) (n exp))

Looks like infinite recursion to me, because earlier you said that
(<integer> <expression>) is translated to (nth <integer> <expression>).
You can't define both of them in terms of each other.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Bill Birch
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <6f7fa60c.0210021649.6aeff89d@posting.google.com>
Barry Margolin <······@genuity.net> wrote in message news:<··············@paloalto-snr1.gtei.net>...
> In article <····························@posting.google.com>,
> Bill Birch <······@ozemail.com.au> wrote:
> >You can define NTH as:
> >
> >   (defun nth (n exp) (n exp))
> 
> Looks like infinite recursion to me, because earlier you said that
> (<integer> <expression>) is translated to (nth <integer> <expression>).
> You can't define both of them in terms of each other.

Sorry, I misled you maybe. Here's what APPLY does inside the interpreter:

   IF the function is an integer
         IF function = 0
               CAR( argument )
         ELSE 
               NTH( func , argument )


So:
   (progn
      (defun nth (n x) (n x))
      (nth 2 '(a b c d e)))

gives ==> c
From: Barry Margolin
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <MkYm9.7$sf4.520@paloalto-snr1.gtei.net>
In article <····························@posting.google.com>,
Bill Birch <······@ozemail.com.au> wrote:
>Barry Margolin <······@genuity.net> wrote in message
>news:<··············@paloalto-snr1.gtei.net>...
>> In article <····························@posting.google.com>,
>> Bill Birch <······@ozemail.com.au> wrote:
>> >You can define NTH as:
>> >
>> >   (defun nth (n exp) (n exp))
>> 
>> Looks like infinite recursion to me, because earlier you said that
>> (<integer> <expression>) is translated to (nth <integer> <expression>).
>> You can't define both of them in terms of each other.
>
>Sorry, I misled you maybe. Here's what APPLY does inside the interpreter:
>
>   IF the function is an integer
>         IF function = 0

Why is this special case necessary?  Can't NTH handle the 0 case?

>               CAR( argument )

Shouldn't this also be conditional on the argument being a cons?  If it's a
vector, this should call AREF.  Of course, you wouldn't need to do this if
you didn't special-case 0, since NTH can handle any sequence type.

>         ELSE 
>               NTH( func , argument )
>
>
>So:
>   (progn
>      (defun nth (n x) (n x))
>      (nth 2 '(a b c d e)))
>
>gives ==> c

Still looks like infinite recursion to me.  When you call (nth 2 '(a b c d
e)) it will invoke (2 '(a b c d e)), and then the section of the
interpreter that you quoted above will invoke NTH(2, '(a b c d e)), which
will continue recursing like this.

Or is the NTH inside the interpreter a different one than the one that's
defined by DEFUN?  Perhaps if you'd called it something like INTERNAL-NTH
that would have been clearer.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Bill Birch
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <6f7fa60c.0210031558.70f88cbd@posting.google.com>
Barry Margolin <······@genuity.net> wrote in message news:<···············@paloalto-snr1.gtei.net>...
> In article <····························@posting.google.com>,
> Bill Birch <······@ozemail.com.au> wrote:
> >Barry Margolin <······@genuity.net> wrote in message
> >news:<··············@paloalto-snr1.gtei.net>...
> >> In article <····························@posting.google.com>,
> >> Bill Birch <······@ozemail.com.au> wrote:
> >> >You can define NTH as:
> >> >
> >> >   (defun nth (n exp) (n exp))
> >> 
> >> Looks like infinite recursion to me, because earlier you said that
> >> (<integer> <expression>) is translated to (nth <integer> <expression>).
> >> You can't define both of them in terms of each other.
> >
> >Sorry, I misled you maybe. Here's what APPLY does inside the interpreter:
> >
> >   IF the function is an integer
> >         IF function = 0
> 
> Why is this special case necessary?  Can't NTH handle the 0 case?
> 
> >               CAR( argument )
> 
> Shouldn't this also be conditional on the argument being a cons?  If it's a
> vector, this should call AREF.  Of course, you wouldn't need to do this if
> you didn't special-case 0, since NTH can handle any sequence type.
> 
> >         ELSE 
> >               NTH( func , argument )
> >
> >
> >So:
> >   (progn
> >      (defun nth (n x) (n x))
> >      (nth 2 '(a b c d e)))
> >
> >gives ==> c
> 
> Still looks like infinite recursion to me.  When you call (nth 2 '(a b c d
> e)) it will invoke (2 '(a b c d e)), and then the section of the
> interpreter that you quoted above will invoke NTH(2, '(a b c d e)), which
> will continue recursing like this.
> 
> Or is the NTH inside the interpreter a different one than the one that's
> defined by DEFUN?  Perhaps if you'd called it something like INTERNAL-NTH
> that would have been clearer.

You're right there is an internal nth in 'C:

Here's the 'C' source below:

car() is a macro:

    #define car(x) (((x)->ztype == PAIR)?(x)->reg.zpair.zcar:\
                     c_error_func("not PAIR for CAR",(x)))

Here's the relevant part of apply:

	....
	else lif( integerp(func) )
	{
		register EXP actuals, result;

         	if( cir(func) == 0 )
         		result = reference(car(car(args)));
         	else
			result = reference(nth( cir(func), car(args)));

			dereference(result);
			return(result);
	}
From: Lieven Marchand
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <87n0pwbqom.fsf@wyrd.be>
······@ozemail.com.au (Bill Birch) writes:

> Paul Graham's web site (www.paulgraham.com) has a neat idea regarding
> compounds in Arc.  e.g.
>    ("helo" 2) ==> \l
> 
>    (a 5) ; instead of Common Lisp (aref a 5)

This has already been discussed in this group (see
<·············@swingandcircle.com> e.g.) and was implemented in
MACLISP decades ago. I don't see why reinventing syntactic sugar is
the next big step for Lisp.

-- 
Hai koe, zei de stier,
Kom mee met mij in de wei,
Dan zijn we tweezaam.
Lieven Marchand <···@wyrd.be>
From: Gareth McCaughan
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <slrnapmmp7.2bbm.Gareth.McCaughan@g.local>
Bill Birch wrote:

> My own dialect of Lisp now has something similar. Integers are allowed
> as special functions! So in RefLisp the following are legal:
> 
>    (0 '(one two)) ==> one  
> 
>    (2 '(one two three)) ==> three
...
> Your views?

It has the same sort of appeal as the fact that you
can say 2["hello, world"] in C and get 'l'.

Why not extend the principle to hash tables? So,
any time you say (x y), your compiler or interpreter
(I'm guessing it's an interpreter, from other things
you wrote) can look to see if y is a hash table,
and if so then it can look up x in it. If x happens
to be a function, then it can choose at random
whether to apply x to y, or look up x in y; I suggest
it should do the former with probability 2/3.

-- 
Gareth McCaughan  ················@pobox.com
.sig under construc
From: Erik Naggum
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <3242588530612895@naggum.no>
* Bill Birch
| Paul Graham's web site (www.paulgraham.com) has a neat idea regarding
| compounds in Arc.

  This "neat idea" dates about about 30 years.  It is most noted for having
  been abandoned.  Ignorants keep reinventing what they do not understand
  are bad ideas until they have tried them for a while.  The basic idea was
  to store an array in the function slot of a symbol.

| Your views?

  If you want this, you have closures and local functions and macros.

(defun foo (string ...)
  (macrolet ((string (n) `(char string ,n)))
    ...
    (string 42)
    ...
    ))

  This even works when the indexes are in variables.  <-- neat idea

-- 
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.
From: Thomas F. Burdick
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <xcv7kh02m49.fsf@hurricane.OCF.Berkeley.EDU>
Erik Naggum <····@naggum.no> writes:

> * Bill Birch
> | Paul Graham's web site (www.paulgraham.com) has a neat idea regarding
> | compounds in Arc.
> 
>   This "neat idea" dates about about 30 years.  It is most noted for having
>   been abandoned.  Ignorants keep reinventing what they do not understand
>   are bad ideas until they have tried them for a while.  The basic idea was
>   to store an array in the function slot of a symbol.
> 
> | Your views?
> 
>   If you want this, you have closures and local functions and macros.
> 
> (defun foo (string ...)
>   (macrolet ((string (n) `(char string ,n)))
>     ...
>     (string 42)
>     ...
>     ))

For what it's worth, I find that local macros like this can make some
code a lot more readable.  I have a macro WITH-REF-LABELS that makes
these MACROLETs for me (they expand into calls to REF, a generic
function I use for generalized dereferencing).  It's similar to
WITH-SLOTS, except that it can be more natural to access arrays (and
hash-tables, and alists, and ...) as functions than as variables.

I mean, for godsakes, if CL is flexible enough to have supported the
addition of CLOS, I don't see why someone would think they needed
language-level support for tables-as-functions.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Vassil Nikolov
Subject: Re: (setq car 0) - Functions on Indices
Date: 
Message-ID: <uadluiyju.fsf@poboxes.com>
    On 2 Oct 2002 00:24:13 -0700, ······@ozemail.com.au (Bill Birch) said:
    [...]
    > Integers are allowed as special functions

It took me some time to realize what sounded so familiar about
this.  Backus's FP uses the positive integers to name the selector
functions; code and data there are very well separated, though.

---Vassil.