Re: Opposite of ~^ FORMAT Directive



Kent,

Kent M Pitman <pitman@xxxxxxxxxxx> writes:
comes to mind, and it's really an ugly trick--but worth knowing, is to
use some sort of circular list thing, as in:
(mapcar #'list ;this mapcar will stop as long as x is not circular!
(cons nil (circular-list t))
x)))

Some people these recent years are extremely pedantic about strict
interpretation of the ANSI-CL (or rather the CLHS), possibly putting
more into its wording than the authors intended to.

One can derive from the entry on MAPCAR:
MAPCAR function &rest lists => result list
Exceptional situations:
Should be prepared to signal an error of type type-error if any list
is not a proper list.
that your code suggestion is not portable code.

However I've come across plenty of (historic?) Lisp code which depends
on this circular list trick wo work with MAPCAR (and other sequence or
list functions). Probably no implementation will choose to signal an
error at the risk of seeing some software library fail (or plainly
because they won't perform an extra check for circular lists) -- or
now that I've pointed at it, they'll change the Lisp implementation
because historic code could be crap ;)

Yet it other areas, these same implementations appear
"plus royaliste que le roi".

E.g. (LENGTH '(2 3 . 4)) signals an error in many implementations,
whereas the MAPCAR trick works. I would have been happy with LENGTH
counting the number of conses reachable from CDR, e.g. 2.

Do you think CL need a CIRCULAR-LIST-ARGUMENTS writeup similar to
DOTTED-LIST-ARGUMENTS?
http://www.lispworks.com/documentation/HyperSpec/Issues/iss138.htm

Regards,
Jorg Hohle
Telekom/T-Systems Technology Center
.



Relevant Pages

  • Re: Opposite of ~^ FORMAT Directive
    ... use some sort of circular list thing, ... (mapcar #'list;this mapcar will stop as long as x is not circular! ... MAPCAR function &rest lists => result list ... but it cannot change the language. ...
    (comp.lang.lisp)
  • Re: mapcar use.
    ... I am still not gettin how to use eval and mapcar to achieve this... ... But I've no idea what the multiplication of two lists can be! ... before the "mapcar road block" is out of the way. ... Tail of black dog keeps good time. ...
    (comp.lang.lisp)
  • Re: Multiple arguments to mapcar?
    ... error if one of the passed lists is not a proper list. ... from the dictionary page of mapcar: ... only circular lists are passed. ...
    (comp.lang.lisp)
  • Re: I still dont get MAPCAN
    ... "mapcan and mapcon are like mapcar and maplist respectively, ... supposed to be the corresponding 'destructive' version of MAPCAR, ... that the function returns a list, and it catenates the lists together. ... the lists returned by the function as if by APPEND rather than NCONC. ...
    (comp.lang.lisp)
  • Re: I still dont get MAPCAN
    ... "mapcan and mapcon are like mapcar and maplist respectively, ... supposed to be the corresponding 'destructive' version of MAPCAR, ... on the contrary you see that the CONS cells of the ... It modified the lists it got ...
    (comp.lang.lisp)