[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
newlispfanclub.alh.net • View topic - (newbie) Listiness

(newbie) Listiness

Q&A's, tips, howto's

(newbie) Listiness

Postby mark5009 » Sat Oct 25, 2014 6:40 am

mark5009
 
Posts: 6
Joined: Sat Oct 25, 2014 6:33 am

Re: (newbie) Listiness

Postby bairui » Sat Oct 25, 2014 12:15 pm

Hi, Mark,

The dolist iterates the list one element at a time. Because you're not printing in that loop, the interpreter is silently throwing away each internal result. Finally the result of the whole loop (its final evaluation) is shown by the interpreter, which is (() 5), as you would expect.

For your stated goal of (() 1 2 3 4 5) you could merely do (cons bar foo)

-- bairui
bairui
 
Posts: 64
Joined: Sun May 06, 2012 2:04 am
Location: China

Re: (newbie) Listiness

Postby mark5009 » Sun Oct 26, 2014 1:57 am

mark5009
 
Posts: 6
Joined: Sat Oct 25, 2014 6:33 am

Re: (newbie) Listiness

Postby saulgoode » Sun Oct 26, 2014 3:53 am

I'm sure there are Newlispers here who will be able to provide a much better solution (probably with just a single function), but nonetheless perhaps some of the following might spawn some ideas for you.

-----------------
> (set 'in-string (read-file "tmp/foo.tmp"))
"# stuff to ignore\n123:avc\n234:vvc\n# more to ignore and the following blank line as well\n\n# and there is the last stuff\n999:xxc\n"

> (set 'all-lines (parse in-string "\n"))
("# stuff to ignore" "123:avc" "234:vvc" "# more to ignore and the following blank line as well"
"" "# and there is the last stuff" "999:xxc" "")

> (set 'non-empty-lines (clean = all-lines)) ; monadic = compares to empty string
("# stuff to ignore" "123:avc" "234:vvc" "# more to ignore and the following blank line as well"
"# and there is the last stuff" "999:xxc")

> (define (comment? s) (starts-with s "#"))
> (set 'lines (clean comment? non-empty-lines))
("123:avc" "234:vvc" "999:xxc")

> (define (split-at-colons s) (parse s ":"))
> (set 'contents (map split-at-colons lines))
(("123" "avc") ("234" "vvc") ("999" "xxc"))
saulgoode
 
Posts: 10
Joined: Sat Jul 16, 2011 6:15 am

Re: (newbie) Listiness

Postby ralph.ronnquist » Sun Oct 26, 2014 5:48 am

ralph.ronnquist
 
Posts: 216
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: (newbie) Listiness

Postby mark5009 » Sun Oct 26, 2014 11:09 pm

Thanks, guys! That is most helpful.

.. mark.
mark5009
 
Posts: 6
Joined: Sat Oct 25, 2014 6:33 am

Re: (newbie) Listiness

Postby tomtoo » Mon Oct 27, 2014 10:23 pm

tomtoo
 
Posts: 46
Joined: Wed Oct 28, 2009 10:00 pm


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest