find-all code in manual not producing expected output

Q&A's, tips, howto's
Locked
joejoe
Posts: 173
Joined: Thu Jun 25, 2009 5:09 pm
Location: Denver, USA

find-all code in manual not producing expected output

Post by joejoe »

I am trying this bit of code from the manual here:

http://www.newlisp.org/downloads/newlis ... l#find-all

Code: Select all

(unique (sort 
    (find-all {[a-zA-Z]+} 
        (replace "<[^>]+>" (get-url "http://newlisp.org") "" 0) )
))
which is said to produce:
→ ("A" "ACC" "AI" "API" "About" "All" "Amazing" "Apps"
...
"where" "whole" "width" "wiki" "will" "with" "work" "written")
but when I run this I get no result at all.

Did something change since this was written or can anyone else say they receive the expected result above?

Thanks! I want to do something very similar and I appreciate the simplicity of being able to do such a thing. :0)

Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

Re: find-all code in manual not producing expected output

Post by Sammo »

Works here running newLISP v.10.2.14 on WinXP. I get the following output:

Code: Select all

("API" "About" "All" "Apps" "Art" "Built" "C" "Cilk" "Development" "Docs" "Documented" 
 "Downloads" "Expandable" "Find" "Forum" "FriendFeed" "Friendly" "GNU" "GPL" "GS" 
 "General" "Gui" "Home" "IDE" "It" "LISP" "LISPs" "Libs" "License" "Links" "Linux" 
 "Lisp" "Mac" "Maintenance" "May" "Modules" "Most" "Movie" "Netscape" "News" "Nuevatec" 
 "OS" "October" "Parallel" "Public" "Read" "Release" "Search" "See" "Server" "Share" 
 "Slideshow" "Stable" "Tips" "Tricks" "Twitter" "UA" "UBUNTU" "Unix" "Watch" "Win" 
 "X" "a" "about" "all" "already" "amp" "and" "are" "area" "arial" "b" "background" 
 "big" "bold" "border" "built" "but" "button" "buttons" "by" "ccc" "changes" "code" 
 "color" "complete" "computing" "copy" "copyright" "courier" "custom" "dashed" "ddd" 
 "decoration" "differs" "displating" "distributed" "divs" "doing" "easier" "edit" 
 "eee" "eef" "entry" "ever" "example" "family" "fast" "features" "files" "follow" 
 "font" "for" "friendly" "from" "functions" "general" "has" "helvetica" "hover" "how" 
 "hr" "if" "img" "in" "installers" "is" "language" "layout" "learn" "left" "libraries" 
 "like" "line" "links" "list" "magic" "margin" "mdash" "mediumred" "modern" "modes" 
 "modules" "more" "most" "mybox" "need" "new" "newLISP" "none" "normal" "not" "of" 
 "on" "operating" "or" "other" "out" "overwritten" "p" "padding" "passwords" "powered" 
 "processing" "purpose" "px" "quick" "referencrs" "reserved" "right" "rights" "runs" 
 "sans" "save" "scripting" "search" "separator" "serif" "server" "shared" "site" 
 "size" "small" "smallred" "solid" "spec" "st" "style" "styles" "support" "systems" 
 "table" "tables" "tag" "tags" "td" "text" "textarea" "th" "the" "these" "thinkHome" 
 "to" "top" "tr" "traditional" "transparent" "uacct" "urchinTracker" "use" "used" 
 "using" "v" "verdana" "version" "weight" "when" "width" "wiki" "will" "with" "work" 
 "written" "you")

joejoe
Posts: 173
Joined: Thu Jun 25, 2009 5:09 pm
Location: Denver, USA

Re: find-all code in manual not producing expected output

Post by joejoe »

newLISP v.10.2.8 on Linux

would this be the reason?

When I say I get no result, I mean that Ive put the code into a text file, saved it and run the script from the shell:

Code: Select all

joe@asdf ~/newlisping $ cat gogo
(unique (sort
    (find-all {[a-zA-Z]+}
        (replace "<[^>]+>" (get-url "http://newlisp.org") "" 0) )
))
(exit)
joe@asdf ~/newlisping $ newlisp gogo
joe@asdf ~/newlisping $
joe@asdf ~/newlisping $ newlisp
newLISP v.10.2.8 on Linux IPv4 UTF-8, execute 'newlisp -h' for more info.

> 
Thanks for help!

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: find-all code in manual not producing expected output

Post by cormullion »

Print the results, then exit....

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: find-all code in manual not producing expected output

Post by Lutz »

The result is the return value of the 'unique' expression. If you run from a file you could either put the whole thing in a "println" statement:

Code: Select all

(println (unique (sort
    (find-all {[a-zA-Z]+}
        (replace "<[^>]+>" (get-url "http://newlisp.org") "" 0) )
)))
(exit)
or you could do an assignment, then print it:

Code: Select all

(set 'result (unique (sort
    (find-all {[a-zA-Z]+}
        (replace "<[^>]+>" (get-url "http://newlisp.org") "" 0) )
)))

(println result)
(exit)
On the latest development versions (currently 10.2.16) you can also paste multi line statements into the interactive newLISP shell:

Code: Select all

~> newlisp        <---- start newLISP in a command shell
newLISP v.10.2.16 on OSX IPv4/6 UTF-8, execute 'newlisp -h' for more info.

>                 <---- hit enter on an empty line at the prompt, then copy paste the code
(unique (sort
    (find-all {[a-zA-Z]+}
        (replace "<[^>]+>" (get-url "http://newlisp.org") "" 0) )
))
                  <---- hit enter again on an empty line to see the result
("API" "About" "All" "Apps" "Art" "Built" "C" "Cilk" "Development" "Docs" "Documented" 
 "Downloads" "Expandable" "Find" "Forum" "FriendFeed" "Friendly" "GNU" "GPL" "GS" 
…
…
 "using" "v" "verdana" "version" "weight" "when" "width" "wiki" "will" "with" "work" 
 "written" "you")
>                 <---- after printing, you get your prompt back
when you hit the [enter] key at the prompt, the prompt disappears and you can enter or paste multi line statements. A second [enter] on an empy line gets you out and evaluates the expression.

NOTE, all this has to be in an interactive shell (e.g. Command shell in Windows, or terminal shell in UNIX) of the operating system. This will not work in the lower window of the newLISP-GS IDE.

joejoe
Posts: 173
Joined: Thu Jun 25, 2009 5:09 pm
Location: Denver, USA

Re: find-all code in manual not producing expected output

Post by joejoe »

Okay, understood completely. Thank you Lutz.

That multi line pasting is a great feature addition! Ive been wondering how to do it for a while! :0)

I appreciate the clarification on the unique experssion. Thank you both again.

Locked