artFlattenList

S

Stefano Zanella

Guest
Hi,

Does anybody know what this function does? I can not find any
reference to in in sourcelink. Is it a private function?

Thanks,
Stefano Zanella
 
Does anybody know what this function does? I can not find any reference
to in in sourcelink. Is it a private function?
apparently, as the name suggests, it flattens a list:

artFlattenList( list(1 2 list('a 'b list("string" 100) 'c 'd) 3 4) ) =>
(1 2 a b "string"
100 c d 3 4
)

if there's no mention anywhere, then it's probably private.

you'd achieve the same with:
procedure( flattenList( x )
apply('nconc mapcar( lambda( (y) if(listp(y) flattenList(y) list(y)) ) x ))
) ; procedure

stéphane
 
On Wed, 13 Apr 2005 11:42:47 +0200, "S. Badel"
<stephane.badel@REMOVETHISepfl.ch> wrote:

Does anybody know what this function does? I can not find any reference
to in in sourcelink. Is it a private function?

apparently, as the name suggests, it flattens a list:

artFlattenList( list(1 2 list('a 'b list("string" 100) 'c 'd) 3 4) ) =
(1 2 a b "string"
100 c d 3 4
)

if there's no mention anywhere, then it's probably private.

you'd achieve the same with:
procedure( flattenList( x )
apply('nconc mapcar( lambda( (y) if(listp(y) flattenList(y) list(y)) ) x ))
) ; procedure

stéphane
Or neater still:

procedure(abFlattenList(l)
if(listp(l) mapcan('abFlattenList l) list(l))
)

And yes, artFlattenList is private. So don't use it.

Andrew.
 
Hi Stepahne and Andrew,

Thanks a lot for your help.
On a slightly related subject, aren't private functions supposed to
start with an underscore?

Regards,
Stefano Zanella

Andrew Beckett wrote:
On Wed, 13 Apr 2005 11:42:47 +0200, "S. Badel"
stephane.badel@REMOVETHISepfl.ch> wrote:


Does anybody know what this function does? I can not find any reference
to in in sourcelink. Is it a private function?

apparently, as the name suggests, it flattens a list:

artFlattenList( list(1 2 list('a 'b list("string" 100) 'c 'd) 3 4) ) =
(1 2 a b "string"
100 c d 3 4
)

if there's no mention anywhere, then it's probably private.

you'd achieve the same with:
procedure( flattenList( x )
apply('nconc mapcar( lambda( (y) if(listp(y) flattenList(y) list(y)) ) x ))
) ; procedure

stéphane


Or neater still:

procedure(abFlattenList(l)
if(listp(l) mapcan('abFlattenList l) list(l))
)

And yes, artFlattenList is private. So don't use it.

Andrew.
 
Hi Stefano,

That's what we do now. However, in the past such rules were not in place
(or at least were not policed). As part of a big effort a few years ago, we
put in place all sorts of processes to ensure that SKILL functions are clearly
marked private/public, that public functions are documented, that new
functions follow certain naming rules. This involves automatically finding new
functions which have been added and checking these, and keeping a database of
functions and their status. (there's a lot more to it than this - this is just
a high level overview).

As part of this there were many functions documented which weren't before.

In general the rule now is that if it is documented, it's public. There are a
very small number of undocumented public functions - the reasons are various,
but the most common is that the function is part of a tool which is going away
or changing, and so its not worth documenting.

We didn't go back and renamed existing functions which didn't follow the new
naming rules because that would:

a) be a huge amount of effort, better spent fixing bugs and adding new
features
b) would unnecessarily disturb people who were using these private functions
(even though they shouldn't have been).

Of course, any function may change if it is private, but there's no point
doing it just for completeness of the naming rules.

Regards,

Andrew.

On Wed, 13 Apr 2005 16:45:29 -0700, Stefano Zanella
<stefanoDOTzanella@pdf.com> wrote:

Hi Stepahne and Andrew,

Thanks a lot for your help.
On a slightly related subject, aren't private functions supposed to
start with an underscore?

Regards,
Stefano Zanella

Andrew Beckett wrote:
On Wed, 13 Apr 2005 11:42:47 +0200, "S. Badel"
stephane.badel@REMOVETHISepfl.ch> wrote:


Does anybody know what this function does? I can not find any reference
to in in sourcelink. Is it a private function?

apparently, as the name suggests, it flattens a list:

artFlattenList( list(1 2 list('a 'b list("string" 100) 'c 'd) 3 4) ) =
(1 2 a b "string"
100 c d 3 4
)

if there's no mention anywhere, then it's probably private.

you'd achieve the same with:
procedure( flattenList( x )
apply('nconc mapcar( lambda( (y) if(listp(y) flattenList(y) list(y)) ) x ))
) ; procedure

stéphane


Or neater still:

procedure(abFlattenList(l)
if(listp(l) mapcan('abFlattenList l) list(l))
)

And yes, artFlattenList is private. So don't use it.

Andrew.
 
procedure(abFlattenList(l)
if(listp(l) mapcan('abFlattenList l) list(l))
)

nice! I didn't know about mapcan, at first I thought it was a typo :)

stéphane
 
On 14 Apr 2005 12:06:11 -0700, jason.dot.jacobs@gmail.com wrote:

Though I think I'll always use
C-syntax for procedure calls.
That's why I decided to be nice and write it in C syntax. I don't want people
to not learn new techniques for doing things, just because they're afraid of
the parentheses!

Cheers,

Andrew.
 
jason.dot.jacobs@gmail.com wrote:
What an eyesore! And it uses append() which probably isn't the most
efficient way to build a list.
Note that many uses of append can be replaced with tconc, though you'll
have to do a bit of rewriting.

tconc (and its cousin, lconc) maintains a pointer to the tail cell of
the list, making it extremely efficient for appends. The trick, though,
is that you have to use car after you're done to get at the list itself.

A tconc cell is a cons cell with the structure:
( head_of_list tail_of_list )

Typical usage, with annotations:
(setq x (tconc nil 1)) ;; Create the first element
;; ((1) 1)
(eq (car x) (cdr x)) ;; t
(tconc x 2) ;; Appends modify the list in-place
;; ((1 2) 2)
(eq (cdar x) (cdr x)) ;; t
(tconc x 3) ;; Another append
;; ((1 2 3) 3)
(eq (cddar x) (cdr x)) ;; t
(car x) ;; Get the list itself
;; (1 2 3)

Though I think I'll always use C-syntax for procedure calls.
Lisp (and, by inheritance, SKILL) uses a powerful model: code is data.
Once you start viewing it from this perspective, it opens up a lot of
doors for metaprogramming. The C syntax is a bit misleading in this
regard -- it makes it look like code exists in some magical code-space.

Tcl is another language which uses this model (there, though, everything
is a string rather than a list). Python and PostScript come close
(everything is a dictionary), but don't quite follow through.

I do prototyping in Python quite frequently anyway, though.

--
David Cuthbert dacut at cadence dot com
Cadence Design Systems +1 (412) 599-1820
 
Andrew Beckett wrote:
Or neater still:

procedure(abFlattenList(l)
if(listp(l) mapcan('abFlattenList l) list(l))
)
Elegant indeed. Examples like give me the urge to dig through my
legacy code to look for ways of doing things in a true Lisp/SKILL
manner. As a guy with a C/C++ background I've neglected uniquely Lisp
things like mapping functions.

This is my version of flatten list (written..hmm... three years ago?):

procedure( JJFlattenList( myList)
let( (rv)
rv = 'nil
if(listp(myList) then
foreach(item myList
rv = append( rv JJFlattenList(item) )
);foreach
else
rv = list( myList )
);if
rv
);let
);procedure

What an eyesore! And it uses append() which probably isn't the most
efficient way to build a list. The more I program in SKILL the more
appreciate the power of this language. Though I think I'll always use
C-syntax for procedure calls.
 

Welcome to EDABoard.com

Sponsor

Back
Top