Search found 180 matches

by Sammo
Fri Apr 01, 2011 3:06 pm
Forum: Anything else we might add?
Topic: all? or perhaps predicates that accept multiple args
Replies: 4
Views: 4050

Re: all? or perhaps predicates that accept multiple args

Thanks, cormullion, for the idioms using exists? and for-all . They are certainly cleaner than my "(apply and (map ...) version. But, Kazimir, your solution is precisely what I was seeking. After creating the various macros, the syntax is as simple as can be, and, by expanding as an explicit and exp...
by Sammo
Thu Mar 31, 2011 11:05 am
Forum: Anything else we might add?
Topic: all? or perhaps predicates that accept multiple args
Replies: 4
Views: 4050

all? or perhaps predicates that accept multiple args

Is there a simple and readable way of applying a predicate to multiple arguments? Perhaps something like: (all? integer? 1 2 3 "string") I know I can write: (apply and (map integer? (list 1 2 3 "string"))) but, actually, I'd like to just write (integer? 1 2 3 "string") which would return false (in t...
by Sammo
Fri Mar 25, 2011 8:38 pm
Forum: newLISP in the real world
Topic: date + parse problems
Replies: 10
Views: 4312

Re: date + parse problems

You'll find that parse correctly handles "Fri Mar 25 07:52:56 2011" and other times with hours less than 8 am, but not "Fri Mar 25 08:52:56 2011". For an extreme case, try "Fri Mar 25 08:08:08 2011". I'll bet this is caused by newLISP's number parser which treats digit strings beginning with "0" as ...
by Sammo
Mon Mar 07, 2011 8:43 pm
Forum: newLISP in the real world
Topic: Another challenge
Replies: 3
Views: 2326

Re: Another challenge

This works but is ugly looking. (map list (sort (flat (dup (sequence 1 5) 4))) (explode (dup "abcd" 5))) With comments: (map list (sort (flat (dup (sequence 1 5) 4))) ;numbers (explode (dup "abcd" 5)) ;letters ) Edit: Simplified expression generating list of letters. Was "(flat (dup (explode "abcd")...
by Sammo
Sun Mar 06, 2011 12:38 pm
Forum: newLISP in the real world
Topic: [solved] OOP
Replies: 8
Views: 3715

Re: Objects

Can you explain why we need letex in this case? Why lambda can't take side from function definition? I am neither a Scheme nor newLisp expert, but I believe the significant difference between them (for this example) lies in a concept called lexical closures . When Scheme executes your make-square c...
by Sammo
Sat Mar 05, 2011 11:25 pm
Forum: newLISP in the real world
Topic: [solved] OOP
Replies: 8
Views: 3715

Re: Objects

A direct translation of the Scheme code to newLisp might be: ; make-square ; 2011-03-05 ; example ; (set 's1 (make-square 2)) ; (s1 'area) ;result = 4 ; (s1 'perimeter) ;result = 8 ; (s1 'xxx) ;result = "unknown message" error (define (make-square side) (letex (s side) (lambda (msg) (cond ((= msg 'a...
by Sammo
Mon Feb 28, 2011 4:53 am
Forum: newLISP in the real world
Topic: This week's challenge
Replies: 15
Views: 4904

Re: This week's challenge

Probably not elegant but it works: (define (magoo list-of-strings) (magoo-aux (sort list-of-strings) '())) (define (magoo-aux list-of-strings list-of-lists) (if (empty? list-of-strings) list-of-lists ;else (local (newlist) (push (pop list-of-strings) newlist) (while (and (not (empty? list-of-strings...
by Sammo
Tue Oct 12, 2010 3:58 am
Forum: newLISP in the real world
Topic: find-all code in manual not producing expected output
Replies: 5
Views: 2394

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

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" "...
by Sammo
Tue May 04, 2010 1:19 am
Forum: newLISP in the real world
Topic: accessing a list number by a symbol for a list
Replies: 3
Views: 1976

Re: accessing a list number by a symbol for a list

Would this work?

Code: Select all

> (set 'record '(("name" "Tim")(age 61))) 
> (set 'ndxs '(a b))
> (set 'a 1 'b 0)
> (record (map eval ndxs))
age
by Sammo
Fri Apr 23, 2010 8:53 pm
Forum: newLISP in the real world
Topic: Stitching lists together
Replies: 5
Views: 2346

Re: Stitching lists together

Another solution:

Code: Select all

(transpose (list a b))
>((fred 1) (jim 2) (bob 3))
and applying transpose again has the effect of undoing:

Code: Select all

(transpose (transpose (list a b)))
>((fred jim bob) (1 2 3))
by Sammo
Wed Apr 21, 2010 3:15 am
Forum: newLISP in the real world
Topic: (parse) oddness
Replies: 7
Views: 3347

Re: (parse) oddness

On Win XP running newLisp 10.2.1, I dup'd your file (complete with \n instead of \r\n) but could not duplicate your symptom. (parse (read-file {C:\MyDirectory\sites-sm.txt}) "\n") returns ("1\tgoogle.com" "2\tfacebook.com" "3\tyahoo.com" "4\tyoutube.com" "5\tlive.com" "6\twikipedia.org" "7\tblogger....
by Sammo
Tue Apr 20, 2010 10:48 pm
Forum: newLISP in the real world
Topic: (parse) oddness
Replies: 7
Views: 3347

Re: (parse) oddness

If there isn't a trailing "\n" in "sites-sm.txt", then is one being appended in (read-file "sites-sm.txt")? It seems that it would have to be in order for trim to correct the problem.
-- Sam
by Sammo
Tue Apr 20, 2010 10:27 pm
Forum: newLISP in the real world
Topic: (parse) oddness
Replies: 7
Views: 3347

Re: (parse) oddness

A trailing "\n" in "sites-sm.txt" is the culprit. Try removing the trailing newlines before parsing:

Code: Select all

(set 'sites (parse (trim (read-file "sites-sm.txt") "" "\n") "\n"))
Edit: Corrected typo
by Sammo
Tue Apr 06, 2010 6:20 pm
Forum: newLISP in the real world
Topic: URL Encode / decode
Replies: 8
Views: 3076

Re: URL Encode / decode

In the Code Snippets example: (define (url-decode str) (replace "+" str " ") ; optional (replace "%([0-9A-F][0-9A-F])" s (char (int $1 0 16)) 1)) should be (define (url-decode str) (replace "+" str " ") ; optional (replace "%([0-9A-F][0-9A-F])" str (char (int $1 0 16)) 1)) in which 's' in the second...
by Sammo
Wed Mar 31, 2010 5:29 pm
Forum: newLISP in the real world
Topic: Finding out complexity of a list
Replies: 4
Views: 1895

Re: Finding out complexity of a list

Maybe ref-all to find reference vectors for all elements, then take the longest vector as the complexity metric? Something like this:

Code: Select all

(apply max (map length (ref-all nil aList (fn (x) true))))
Edit: Clarified list parameter in ref-all.
by Sammo
Mon Mar 29, 2010 4:57 pm
Forum: newLISP newS
Topic: Manual Notes 10.2.1
Replies: 37
Views: 19406

Manual Notes 10.2.1

In the documentation for 'explode', ...

Code: Select all

; omit last chunk if too short
(explode '(a b c d e f g h) 2 true)  → ((a b) (c d) (e f))
should be:

Code: Select all

; omit last chunk if too short
(explode '(a b c d e f g) 2 true)  → ((a b) (c d) (e f))
by Sammo
Mon Mar 22, 2010 11:46 pm
Forum: newLISP in the real world
Topic: Function dispatch or callback list
Replies: 5
Views: 2622

Re: Function dispatch or callback list

In 'funcs' you are storing the names of functions 'do-int' and 'do-text' but not the functions themselves. Writing it slightly differently, (define (do-int arg1 arg2) (println "DO-INT - arg1: " arg1 " arg2: " arg2) ) (define (do-text arg1 arg2) (println "DO-TEXT - arg1: " arg1 " arg2: " arg2) ) (set...
by Sammo
Tue Jan 05, 2010 12:52 am
Forum: newLISP in the real world
Topic: newLISP-gs opens only splash picture
Replies: 9
Views: 2938

Re: newLISP-gs opens only splash picture

For windows

Code: Select all

(device (open "nul" "write"))
by Sammo
Sun Sep 13, 2009 8:56 pm
Forum: newLISP in the real world
Topic: Replace Surprise
Replies: 4
Views: 1882

Probably because replace is destructive and the 2nd and 3rd times through the loop, the argument to replace is "hej, first" instead of "hej, x" so that (replace "x" ...) doesn't find an "x" to replace.
by Sammo
Mon Aug 31, 2009 8:33 pm
Forum: newLISP newS
Topic: newLISP 10.1.2 issues
Replies: 17
Views: 9494

In this code (dolist (n number-list (!= (mod n 2) 0) ) (println (/ n 2)) ) symbol n is assigned the value of an element of number-list after which function (!= (mod n 2) 0) is evaluated. If number-list has no elements, the dolist function terminates without having evaluated the [exp-break] function ...
by Sammo
Mon Aug 31, 2009 7:51 pm
Forum: newLISP newS
Topic: newLISP 10.1.2 issues
Replies: 17
Views: 9494

Work for me after replacing the ASCII 92 character you used as a single quote with a bonafide single quote character ASCII 27. Here is the working code:

(define number-list '(100 300 500 701 900 1100 1300 1500))
(dolist (n number-list (!= (mod n 2) 0))
(println (/ n 2)))
by Sammo
Fri Aug 03, 2007 11:58 pm
Forum: Anything else we might add?
Topic: LISP Cycles (humor)
Replies: 1
Views: 1995

LISP Cycles (humor)

by Sammo
Sun Feb 18, 2007 5:05 pm
Forum: newLISP newS
Topic: new Movie
Replies: 2
Views: 2337

Extremely nice video -- thank you Michael.

Lutz, at http://newlisp.org the word "Whatch" should be "Watch".
by Sammo
Wed Dec 27, 2006 7:57 pm
Forum: newLISP newS
Topic: Release 9.0.12
Replies: 4
Views: 3538

~ was still on 32 bits
Thanks for fixing ~. I was wondering why my crc16 code had stopped working. Until today I had been using a pre-8.9.7 dll because of that problem. Now it's fixed and I'm back in step with everyone else.

-- Sam
by Sammo
Wed Dec 27, 2006 7:54 pm
Forum: Anything else we might add?
Topic: Offtopic: Math puzzle!
Replies: 1
Views: 1762

It IS funny .. thanks for sharing.
-- Sam