Search found 180 matches
- 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: 4085
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...
- 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: 4085
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...
- Fri Mar 25, 2011 8:38 pm
- Forum: newLISP in the real world
- Topic: date + parse problems
- Replies: 10
- Views: 4342
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 ...
- Mon Mar 07, 2011 8:43 pm
- Forum: newLISP in the real world
- Topic: Another challenge
- Replies: 3
- Views: 2342
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")...
- Sun Mar 06, 2011 12:38 pm
- Forum: newLISP in the real world
- Topic: [solved] OOP
- Replies: 8
- Views: 3754
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...
- Sat Mar 05, 2011 11:25 pm
- Forum: newLISP in the real world
- Topic: [solved] OOP
- Replies: 8
- Views: 3754
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...
- Mon Feb 28, 2011 4:53 am
- Forum: newLISP in the real world
- Topic: This week's challenge
- Replies: 15
- Views: 4925
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...
- 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: 2422
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" "...
- 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: 2001
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
- Fri Apr 23, 2010 8:53 pm
- Forum: newLISP in the real world
- Topic: Stitching lists together
- Replies: 5
- Views: 2362
Re: Stitching lists together
Another solution:
and applying transpose again has the effect of undoing:
Code: Select all
(transpose (list a b))
>((fred 1) (jim 2) (bob 3))
Code: Select all
(transpose (transpose (list a b)))
>((fred jim bob) (1 2 3))
- Wed Apr 21, 2010 3:15 am
- Forum: newLISP in the real world
- Topic: (parse) oddness
- Replies: 7
- Views: 3380
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....
- Tue Apr 20, 2010 10:48 pm
- Forum: newLISP in the real world
- Topic: (parse) oddness
- Replies: 7
- Views: 3380
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
-- Sam
- Tue Apr 20, 2010 10:27 pm
- Forum: newLISP in the real world
- Topic: (parse) oddness
- Replies: 7
- Views: 3380
Re: (parse) oddness
A trailing "\n" in "sites-sm.txt" is the culprit. Try removing the trailing newlines before parsing:
Edit: Corrected typo
Code: Select all
(set 'sites (parse (trim (read-file "sites-sm.txt") "" "\n") "\n"))
- Tue Apr 06, 2010 6:20 pm
- Forum: newLISP in the real world
- Topic: URL Encode / decode
- Replies: 8
- Views: 3102
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...
- Wed Mar 31, 2010 5:29 pm
- Forum: newLISP in the real world
- Topic: Finding out complexity of a list
- Replies: 4
- Views: 1911
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:
Edit: Clarified list parameter in ref-all.
Code: Select all
(apply max (map length (ref-all nil aList (fn (x) true))))
- Mon Mar 29, 2010 4:57 pm
- Forum: newLISP newS
- Topic: Manual Notes 10.2.1
- Replies: 37
- Views: 19565
Manual Notes 10.2.1
In the documentation for 'explode', ...
should be:
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))
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))
- Mon Mar 22, 2010 11:46 pm
- Forum: newLISP in the real world
- Topic: Function dispatch or callback list
- Replies: 5
- Views: 2644
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...
- Tue Jan 05, 2010 12:52 am
- Forum: newLISP in the real world
- Topic: newLISP-gs opens only splash picture
- Replies: 9
- Views: 2948
Re: newLISP-gs opens only splash picture
For windows
Code: Select all
(device (open "nul" "write"))
- Sun Sep 13, 2009 8:56 pm
- Forum: newLISP in the real world
- Topic: Replace Surprise
- Replies: 4
- Views: 1894
- Mon Aug 31, 2009 8:33 pm
- Forum: newLISP newS
- Topic: newLISP 10.1.2 issues
- Replies: 17
- Views: 9572
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 ...
- Mon Aug 31, 2009 7:51 pm
- Forum: newLISP newS
- Topic: newLISP 10.1.2 issues
- Replies: 17
- Views: 9572
- Fri Aug 03, 2007 11:58 pm
- Forum: Anything else we might add?
- Topic: LISP Cycles (humor)
- Replies: 1
- Views: 2004
- Sun Feb 18, 2007 5:05 pm
- Forum: newLISP newS
- Topic: new Movie
- Replies: 2
- Views: 2352
Extremely nice video -- thank you Michael.
Lutz, at http://newlisp.org the word "Whatch" should be "Watch".
Lutz, at http://newlisp.org the word "Whatch" should be "Watch".
- Wed Dec 27, 2006 7:57 pm
- Forum: newLISP newS
- Topic: Release 9.0.12
- Replies: 4
- Views: 3550
- Wed Dec 27, 2006 7:54 pm
- Forum: Anything else we might add?
- Topic: Offtopic: Math puzzle!
- Replies: 1
- Views: 1772