all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: lisp style question
       [not found] ` <82vd3ceexc.fsf@shevek.netfonds.no>
@ 2010-12-03  1:11   ` Katalin Sinkov
       [not found]     ` <87zkslgk3c.fsf@mail.geddis.org>
  2010-12-05 20:51     ` RG
  0 siblings, 2 replies; 5+ messages in thread
From: Katalin Sinkov @ 2010-12-03  1:11 UTC (permalink / raw)
  To: help-gnu-emacs

On Dec 2, 12:50 am, "Frode V. Fjeld" <fr...@netfonds.no> wrote:
> Katalin Sinkov <lispstyl...@gmail.com> writes:
> > In the {} world I would return a small table like
>
> > width   1
> > height  2
> > weight  3
>
> Typically in Lisp you'd return either a property or association list.
>
> I.e: (WIDTH 1 HEIGHT 2 WEIGHT 3) with accessor GETF,
>
> or ((WIDTH . 1) (HEIGHT . 2) (WEIGHT . 3)) with accessor ASSOC.
>
> --
> Frode V. Fjeld

Of all the four or five replies, I found yours most helpful although
brief. This is perhaps due to me being a beginner, although the
replies seem very promising and I am desirous of understanding them. I
have just read the paper by McCarthy and the micro manual.

assoc. and pair. are the most elementary of the functions, although
not primitive and used in evaluator for working the symbol table.

but beyond this, i could not understand your post.

what is an "assoc list" and "a property list" and their difference ?

what is "setf" and how to write it in terms of the elementary
functions, car/cdr/cons/quote/cond/atom/eq ?

how to conveniently costruct the list that goes with getf ?

Presently I use the emacs IDE only and restricted to elisp, though i
can (require 'cl) so what are
the correponding operation in elisp ?

what are the corresponding functions to defclass/defstruct in elisp ?
I assume people are assuming CL.

Could you comment a little on the post of Captain Obvious and Pascal
Bourguignon ?

The former has "values" and the latter has "make-volume" and colons.
How did the constructor "make-volume" come to be ?

Is it a feature in elisp ?

Thanks for your help.

Katalin


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: lisp style question
       [not found]     ` <87zkslgk3c.fsf@mail.geddis.org>
@ 2010-12-05 18:22       ` Katalin Sinkov
  0 siblings, 0 replies; 5+ messages in thread
From: Katalin Sinkov @ 2010-12-05 18:22 UTC (permalink / raw)
  To: help-gnu-emacs

On Dec 4, 4:05 pm, Don Geddis <d...@geddis.org> wrote:
> Katalin Sinkov <lispstyl...@gmail.com> wrote on Thu, 2 Dec 2010 :
>
> > what is "setf" and how to write it in terms of the elementary
> > functions, car/cdr/cons/quote/cond/atom/eq ?
>
> Unlike your subject line, this is no longer a "lisp style" question.

> That's fine, but before asking "style" questions, you ought to learn
> some lisp.  Get an introductory tutorial (there are good free ones
> online!), try some examples.  After you learn a bit of lisp, and can
> write simple programs, perhaps then you can come back with some style
> questions.

OK, I read the papers by McCarthy and the evaluator.

> You just don't know lisp.

Do you know lisp ? Do you even know how to fork off another thread if
that is your issue with the heading ? Also, style cannot be decoupled
from skill of language. Even if you learnt all the C, you could not
write a C++ style virtual class in it unless you had the skill. The
most you would be able to achieve would be methods with function
pointers.

> Oh, and by the way: the functions your listed are not "the elementary
> functions" (lisp has lots of functions, and there is no unique
> elementary subset); nor can SETF be written in terms of the ones you
> listed.

But you have one set provided to you on silver plate to use. Must I
provide you with all of them before you will activate your neuron and
lift your finger to explain how setf is implemented ?

HTH

>         -- Don
> ___________________________________________________________________________­____
> Don Geddis                  http://don.geddis.org/              d...@geddis.org
> You see, wire telegraph is a kind of a very, very long cat. You pull his tail
> in New York and his head is meowing in Los Angeles.  Do you understand this?
> And radio operates exactly the same way: you send signals here, they receive
> them there.  The only difference is that there is no cat.
>         -- Albert Einstein, when asked to describe radio



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: lisp style question
  2010-12-03  1:11   ` Katalin Sinkov
       [not found]     ` <87zkslgk3c.fsf@mail.geddis.org>
@ 2010-12-05 20:51     ` RG
       [not found]       ` <87aakjkg2i.fsf@kuiper.lan.informatimago.com>
  1 sibling, 1 reply; 5+ messages in thread
From: RG @ 2010-12-05 20:51 UTC (permalink / raw)
  To: help-gnu-emacs

In article 
<6e2fe51c-ff4c-429f-b221-a3cbe23e958f@n2g2000pre.googlegroups.com>,
 Katalin Sinkov <lispstylist@gmail.com> wrote:

> On Dec 2, 12:50 am, "Frode V. Fjeld" <fr...@netfonds.no> wrote:
> > Katalin Sinkov <lispstyl...@gmail.com> writes:
> > > In the {} world I would return a small table like
> >
> > > width   1
> > > height  2
> > > weight  3
> >
> > Typically in Lisp you'd return either a property or association list.
> >
> > I.e: (WIDTH 1 HEIGHT 2 WEIGHT 3) with accessor GETF,
> >
> > or ((WIDTH . 1) (HEIGHT . 2) (WEIGHT . 3)) with accessor ASSOC.
> >
> > --
> > Frode V. Fjeld
> 
> Of all the four or five replies, I found yours most helpful although
> brief. This is perhaps due to me being a beginner, although the
> replies seem very promising and I am desirous of understanding them. I
> have just read the paper by McCarthy and the micro manual.

There's another solution that doesn't seem to have been mentioned yet:

? (defstruct thing width height weight)
THING
? (setf thing (make-thing :width 1 :height 2 :weight 3))
#S(THING :WIDTH 1 :HEIGHT 2 :WEIGHT 3)
? (thing-height thing)
2
? (slot-value thing 'height)
2

> what is an "assoc list" and "a property list" and their difference ?

The difference is purely one of convention.  Both are simple 
arrangements of cons cells, but an association list (also called an 
assoc list of an a-list) looks like this:

((key . value) (key . value) ...)

while a property list (also called a p-list) looks like this:

(key value key value ...)

These are not the only ways to create associative maps using cons cells.  
For example, there is a little-used convention that I call a D-List (for 
"dissociated association list") that looks like this:

((key key ...) value value ...)

The advantage of a D-List is that multiple D-List can share the same set 
of keys so if you have a lot of associative maps with the same keys this 
can be a big performance win.  There are lots of other efficiency hacks 
you can do on D-Lists that you can't do on A-Lists or P-Lists, but 
that's probably more advanced than you want to get right now.

> what is "setf" and how to write it in terms of the elementary
> functions, car/cdr/cons/quote/cond/atom/eq ?

SETF is a macro, not a function, and a particularly complicated one.  
You should read up on macros in general before trying to understand how 
SETF is implemented.

> how to conveniently costruct the list that goes with getf ?

You can't construct anything with GETF.  GETF is an accessor.

rg


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: lisp style question
       [not found]       ` <87aakjkg2i.fsf@kuiper.lan.informatimago.com>
@ 2010-12-06  5:45         ` RG
  0 siblings, 0 replies; 5+ messages in thread
From: RG @ 2010-12-06  5:45 UTC (permalink / raw)
  To: help-gnu-emacs

In article <87aakjkg2i.fsf@kuiper.lan.informatimago.com>,
 "Pascal J. Bourguignon" <pjb@informatimago.com> wrote:

> RG <rNOSPAMon@flownet.com> writes:
> 
> > In article 
> > <6e2fe51c-ff4c-429f-b221-a3cbe23e958f@n2g2000pre.googlegroups.com>,
> >  Katalin Sinkov <lispstylist@gmail.com> wrote:
> >
> >> how to conveniently costruct the list that goes with getf ?
> >
> > You can't construct anything with GETF.  GETF is an accessor.
> 
> This is not correct.  GETF is special:
> 
> CL-USER> (let ((plist '()))
>            (setf (getf plist :k1) 1
>                  (getf plist :k2) 2)
>            plist)
> (:K2 2 :K1 1)
> 
> Setfers are able to do such things.

GETF is not unique in this regard.  GETHASH works the same way.  But 
relying on GETF's ability to allocate storage for new keys is fraught 
with peril, e.g.:

(defun make-new-plist () (list :key1 :value1))

(defun set-key (plist key value)
  (setf (getf plist key) value))

(defun foo ()
  (let* ((plist (make-new-plist)))
    (set-key plist :key1 :new-value-1)
    (set-key plist :key2 :value2)
    plist))

(foo) ==> (:KEY1 :NEW-VALUE-1)  ; What happened to key2?

I think it's better to advise beginners to avoid such things rather than 
try to explain the sometimes subtle distinction between places and 
first-class mutable data objects.

rg


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: lisp style question
@ 2012-11-05 23:33 Rivka Miller
  0 siblings, 0 replies; 5+ messages in thread
From: Rivka Miller @ 2012-11-05 23:33 UTC (permalink / raw)
  To: help-gnu-emacs

On Dec 2 2010, 5:11 pm, Katalin Sinkov <lispstyl...@gmail.com> wrote:
> On Dec 2, 12:50 am, "Frode V. Fjeld" <fr...@netfonds.no> wrote:
>
> > Katalin Sinkov <lispstyl...@gmail.com> writes:
> > > In the {} world I would return a small table like
>
> > > width   1
> > > height  2
> > > weight  3
>
> > Typically in Lisp you'd return either a property or association list.
>
> > I.e: (WIDTH 1 HEIGHT 2 WEIGHT 3) with accessor GETF,
>
> > or ((WIDTH . 1) (HEIGHT . 2) (WEIGHT . 3)) with accessor ASSOC.
>
> > --
> > Frode V. Fjeld
>
> Of all the four or five replies, I found yours most helpful although
> brief. This is perhaps due to me being a beginner, although the
> replies seem very promising and I am desirous of understanding them. I
> have just read the paper by McCarthy and the micro manual.

> assoc. and pair. are the most elementary of the functions, although
> not primitive and used in evaluator for working the symbol table.

> but beyond this, i could not understand your post.

> what is an "assoc list" and "a property list" and their difference ?

> what is "setf" and how to write it in terms of the elementary
> functions, car/cdr/cons/quote/cond/atom/eq ?

I have a few questions about this post from the past that I stumbled.
http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/fe797358c6550f1d/

Are these "car/cdr/cons/quote/cond/atom?/eq?" the only seven
primitives needed to describe a minimal lisp?

What about the values NIL or can it be described as () and is implicit
in cons - and how?

In addition, are not the concepts, lambda, and label needed as
primitives to define the auxiliary functions assoc. and pair. to
access and construct the environment? If that the primitive lambda is
an abstraction specifier (for free variable binding specification),
then it cannot be used as a function identifier or an operation name.

> how to conveniently costruct the list that goes with getf ?

> Presently I use the emacs IDE only and restricted to elisp, though i
> can (require 'cl) so what are
> the correponding operation in elisp ?
>
> what are the corresponding functions to defclass/defstruct in elisp ?
> I assume people are assuming CL.
>
> Could you comment a little on the post of Captain Obvious and Pascal
> Bourguignon ?
>
> The former has "values" and the latter has "make-volume" and colons.
> How did the constructor "make-volume" come to be ?
>
> Is it a feature in elisp ?
>
> Thanks for your help.
>
> Katalin

Thanks.
Rivka




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-11-05 23:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-05 23:33 lisp style question Rivka Miller
     [not found] <ef033328-1f7d-49e9-8b1b-1e4e1f6edcb5@d8g2000yqf.googlegroups.com>
     [not found] ` <82vd3ceexc.fsf@shevek.netfonds.no>
2010-12-03  1:11   ` Katalin Sinkov
     [not found]     ` <87zkslgk3c.fsf@mail.geddis.org>
2010-12-05 18:22       ` Katalin Sinkov
2010-12-05 20:51     ` RG
     [not found]       ` <87aakjkg2i.fsf@kuiper.lan.informatimago.com>
2010-12-06  5:45         ` RG

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.