This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Suggestion for strings.c


Michael Livshin <mlivshin@bigfoot.com> writes:

> Jost Boekemeier <jostobfe@calvados.zrz.TU-Berlin.DE> writes:
> 
> > >  (let* ((v (gensym 'location-value))
> > >        (trans `(make-procedure-with-setter
> > >                  (lambda () ,place)
> > >                  (lambda (,v) (set! ,place ,v)))))
> > 
> > Does this mean that generalized set! is actually a procedure call?!?
> 
> no.  this means that "dereferincing" a location is a procedure call.
> nothing to do with set! per se.

Hmm?  Replace the above "(set! ,place ,v)" with "(format-hard-disk)"
if you still don't understand what I mean.  -- I wouldn't expect
(set! (s o) v) to do something like that.


> > I hope not.  From reading the SRFI I got the impression that:
> > 
> > a) it suggests that a "getter" procedure returns a location and
> >    set! changes this location.
> 
> wrong.  it suggests that a getter returns a value, and (setter getter) 
> returns a procedure that changes that value.  nothing to do with locations.

[From the SRFI]

Rationale

Many programming languages have the concept of an lvalue. that is an
"expression" that "evaluates" to a location, and which can appear on
the left-hand-side of an assignment. Common Lisp has a related concept
of "generalized variables" which can be used in setf and some other
special forms. However, the Common Lisp concept is based on the idea
of compile-time recognition of special "location-producing" functions;
this does not seem to be in the "spirit of Scheme".


> > b) this is not how it is implemented.  In fact (set! (getter object) val)
> >    is just syntactic shugar for (setter object val).
> 
> what do you mean by "not how it is implemented"?  

[From the SRFI]

Specification

The special form set! is extended so the first operand can be a
procedure application, and not just a variable. The procedure is
typically one that extracts a component from some data
structure. Informally, when the procedure is called in the first
operand of set!, it causes the corresponding component to be replaced
by the second operand. For example,

(set (vector-ref x i) v)

would be equivalent to: 

(vector-set! x i v)

Each procedure that may be used as the first operand to set! must have
a corresponding "setter" procedure. The builtin procedure setter takes
a procedure and returns the corresponding setter procedure.


> > I think that both a) and b) are dangerous (and of course their
> > combination is even more dangerous):


--------------------------------------------------
And now something different:

> Goops objects don't protect themselves from being modified.

Amen.  What do generics do?  Yes, right, they implement messages 
which can be send to different objects.  Once dispatched the
concrete function can only operate on the object internals, not
on internals of different objects.

<int>suprise         : prints "hello" and sets it to 0
<string>surprise     : prints string and sets it to ""
<harddisk>surprise   : prints a message and formats hd


> >
> >     As you probably know a location may either be exported
> > 
> >     1 not exported at all
> > 
> >     2 immutable
> > 
> >     3 mutable but specified modification (see set-validate-counter-value)
> > 
> >     4 mutable
> 
> no, I don't know that.  does the above have any relation to Scheme?

GOOPS, Michael, we're talking about GOOPS.  Have you looked at it?
Do you know what #:getter and #:setter do?

Okay, here's the translation:

1  virtual slot

2 only a getter

3 a getter with a setter

4 n.a. (slot-set! but that should not be used)

You could argue that generalized set! can be used for type 4.
But this is actually not the case.  You argue that generalized set!
can also be used for type 3 which is dangerous.


> >     The problem is here that generalized set! is not general enough as
> >     it can only be used to change type 4 locations.  Also the syntax
> >     (set! (x y) val) is a bad replacement for the more descriptive setter
> >     "set-counter-value".
> 
> leaving aside the question of taste (I think it's a good replacement), 
> you are wrong here.  you set the setter to set-validate-counter-value, 
> et voila.

Or even better to: "format-hard-disk".  From the Emacs distribution:



GNUecho(1)	    UNIX Programmer's Manual	       GNUecho(1)



NAME
     echo - echo arguments

SYNOPSIS
     echo [ options ] ...

DESCRIPTION
     Echo writes its arguments separated by blanks and terminated
     by	a newline on the standard output.  Options to filter and
     redirect the output are as	follows:

     -2	  generate rhyming couplets from keywords

     -3	  generate Haiku verse from keywords

     -5	  generate limerick from keywords

     -a	  convert ASCII	to ASCII

     -A	  disambiguate sentence	structure

     -b	  generate bureaucratese equivalent (see -x)

     -B	  issue	equivalent C code with bugs fixed

     -c	  simplify/calculate arithmetic	expression(s)

     -C	  remove copyright notice(s)

     -d	  define new echo switch map

     -D	  delete all ownership information from	system files

     -e	  evaluate lisp	expression(s)

     -E	  convert ASCII	to Navajo

     -f	  read input from file

     -F	  transliterate	to french

     -g	  generate pseudo-revolutionary	marxist	catch-phrases

     -G	  prepend GNU manifesto

     -h	  halt system (reboot suppressed on Suns, Apollos, and
	  VAXen, not supported on NOS-2)

     -i	  emulate IBM OS/VU (recursive universes not supported)

     -I	  emulate IBM VTOS 3.7.6 (chronosynclastic infundibulae
	  supported with restrictions documented in IBM	VTOS


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]