find-all code in manual not producing expected output

Started by joejoe, October 11, 2010, 07:50:14 PM

Previous topic - Next topic

joejoe

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



http://www.newlisp.org/downloads/newlisp_manual.html#find-all">http://www.newlisp.org/downloads/newlis ... l#find-all">http://www.newlisp.org/downloads/newlisp_manual.html#find-all


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


which is said to produce:


Quote→ ("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

Works here running newLISP v.10.2.14 on WinXP. I get the following output:
("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

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:


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

Print the results, then exit....

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:

(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:
(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:
~> 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

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.