Search found 595 matches

by rickyboy
Fri Oct 11, 2019 11:40 pm
Forum: newLISP in the real world
Topic: values into mul
Replies: 2
Views: 575

Re: values into mul

Use read-expr.

Code: Select all

(println (mul 2 (read-expr abc)))
by rickyboy
Fri Sep 20, 2019 5:30 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 2072

Re: Timing function problem

Over time envrironment and stack memory gets fragmented by certain functions. The error forces a total low level freeing and reallocation of this memory. There is nothing we can do about it without slowing down everywhere, but it is a rare enough problem. Until now, I have never seen this before. T...
by rickyboy
Fri Sep 20, 2019 1:36 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 2072

Re: Timing function problem

cameyo, thank you for raising this issue!
by rickyboy
Fri Sep 20, 2019 12:44 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 2072

Re: Timing function problem

@rickyboy and @ralph.ronnquist Sorry, I didn't explain myself well. The function i tried was "merge" with temporary heap function. Yes, you are correct. I remember testing this myself before I first posted here (as I had the same idea as Ralph). I ruled that out as a possibility when I saw what you...
by rickyboy
Thu Sep 19, 2019 10:01 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 2072

Re: Timing function problem

I upgraded my newLISP. Still works fine. $ ./newlisp newLISP v.10.7.5 64-bit on BSD IPv4/6 UTF-8 libffi, options: newlisp -h > (define (merge lstA lstB op) (sort (append lstA lstB) op)) (lambda (lstA lstB op) (sort (append lstA lstB) op)) > (time (merge (sequence 1 500) (sequence 1 200) <) 500) 594....
by rickyboy
Thu Sep 19, 2019 7:06 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 2072

Re: Timing function problem

@ralph.ronnquist: I have tried your function (in a fresh REPL), but the result are the same: > (time (merge (sequence 1 500) (sequence 1 200) <) 500) 1842.392 > (time (merge (sequence 1 500) (sequence 1 200) <) 500) 2290.107 > (time (merge (sequence 1 500) (sequence 1 200) <) 500) 2831.184 > (time ...
by rickyboy
Wed Sep 18, 2019 5:29 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 2072

Re: Timing function problem

P.S. Calling your merge function with smaller inputs doesn't cause a ramp up of timings. (setq C '(4 3 2)) (setq D '(8 5 3 1)) (time (merge C D >) 500) Here's the REPL output as I continually press Ctrl-x Ctrl-e (newlisp-eval) with my cursor on the time call (in Emacs). > 2.712 > 2.777 > 2.682 > 2.6...
by rickyboy
Wed Sep 18, 2019 5:17 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 2072

Re: Timing function problem

Yeah, I don't know precisely what's causing that, but when you use a loop (instead of an iterative recursive call), this problem goes away. (define (merge-via-loop lstA lstB op) (let (out '()) (until (or (null? lstA) (null? lstB)) (push (if (op (first lstB) (first lstA)) (pop lstB) (pop lstA)) out -...
by rickyboy
Tue Sep 03, 2019 6:03 pm
Forum: newLISP in the real world
Topic: what's wrong with the use of apply append
Replies: 4
Views: 661

Re: what's wrong with the use of apply append

The symbol 'var which is passed to "append" has been binded to "b", why is the evaluator not able to see it? The short answer is: because the quote prevents it from getting evaluated, as in: > (setq var "b") "b" > 'var var > var "b" Here, the single quote character (preceding var ) prevents var fro...
by rickyboy
Tue Sep 03, 2019 9:49 am
Forum: newLISP in the real world
Topic: what's wrong with the use of apply append
Replies: 4
Views: 661

Re: what's wrong with the use of apply append

What we were missing was the error message: > (setq var "b") "b" > (apply append '("a" var)) ;; I believe the result will be "ab", but what I get is error message. ERR: string expected in function append : 'var The problem is that in the expression '("a" var) , var is getting quoted; so, you end up ...
by rickyboy
Wed Aug 28, 2019 12:43 am
Forum: newLISP in the real world
Topic: Create polynomials
Replies: 3
Views: 759

Re: Create polynomials

Here's a version of the lambda builder that constructs the body according to the method of Horner . (define (make-poly-horner coeffs) (push (if (< (length coeffs) 2) (first coeffs) (apply (fn (acc c) (list 'add c (cons 'mul (list 'x acc)))) coeffs 2)) (copy '(fn (x))) -1)) To give you an idea of wha...
by rickyboy
Sat Jul 13, 2019 9:04 pm
Forum: newLISP in the real world
Topic: Pathological floating point problems
Replies: 2
Views: 654

Re: Pathological floating point problems

That's very cool. And a good thing to keep in mind when doing computer arithmetic. But, your code could be much shorter -- it would then be more readable to others (and to you, months or years later :). (define (rat n d) (let (g (gcd n d)) (map (curry * 1L) (list (/ n g) (/ d g))))) (define (+rat r1...
by rickyboy
Sat Jul 13, 2019 6:00 pm
Forum: Whither newLISP?
Topic: pseudo-random number generator
Replies: 1
Views: 1585

Re: pseudo-random number generator

I'm not an expert at PRNGs, but here is the implementation in newlisp.

https://github.com/kosh04/newlisp/blob/ ... 1709-L1764
by rickyboy
Mon Jun 03, 2019 10:35 am
Forum: newLISP in the real world
Topic: Sum of digits
Replies: 4
Views: 984

Re: Sum of digits

by rickyboy
Sat Jun 01, 2019 11:37 pm
Forum: newLISP newS
Topic: newLISP language support for Visual Studio Code
Replies: 9
Views: 3230

Re: newLISP language support for Visual Studio Code

Nice!

I would collab but I don't use VS Code (nor linux, nor windows, nor mac). :)

(However, I just sent a PR on your other gh project.) Best, --Rick
by rickyboy
Thu May 30, 2019 9:18 pm
Forum: newLISP in the real world
Topic: Maximum Product Sublist
Replies: 5
Views: 932

Re: Maximum Product Sublist

Hi rickyboy Hi cameyo! :) the sublist must contains only contiguous elements. But your functions are useful anyway :-) Ah, ok! Then my updated maxProd function is still very similar to my original. (define (maxProd lst) ;; lst must contain integers; note use of integer op `*`. (apply max (map (fn (...
by rickyboy
Thu May 30, 2019 6:57 pm
Forum: newLISP in the real world
Topic: Maximum Product Sublist
Replies: 5
Views: 932

Re: Maximum Product Sublist

Here's my version. (define (maxProd lst) ;; lst must contain integers; note use of integer op `*`. (apply max (map (fn (prods) (apply * prods)) (remove '() (powerset lst))))) You'll need these functions. (define (mappend) (apply append (apply map (args)))) (define (powerset s) (if s (mappend (fn (x)...
by rickyboy
Thu May 30, 2019 6:08 pm
Forum: newLISP in the real world
Topic: Group the elements of a list
Replies: 10
Views: 1540

Re: Group the elements of a list

While I was exploring all the code, I believe that I found a bug. The following identity should hold: the reachability of the transitive closure of input is the same as the reachability of input . > (set-equal? (reachability input) (reachability (transD input))) nil Hmmm. What's going on? > (reachab...
by rickyboy
Thu May 30, 2019 5:42 pm
Forum: newLISP in the real world
Topic: Group the elements of a list
Replies: 10
Views: 1540

Re: Group the elements of a list

Then, how do you go the other way? I.e. how do you reduce into the smallest number of pairs, or at least find a sub list so that implied relationships are omitted from the list? Well, I perceive that you know the answer already, so I thank you for letting us share in the fun. :) Here is a function ...
by rickyboy
Wed May 29, 2019 11:29 pm
Forum: newLISP in the real world
Topic: Group the elements of a list
Replies: 10
Views: 1540

Re: Group the elements of a list

A recursive solution could be something like this: (define (trans s (x s) (f (and s (curry intersect (first s))))) (if s (trans (rest s) (cons (unique (flat (filter f x))) (clean f x))) x)) Perhaps there is something faster. Looks good, Ralph! I don't think I could do it faster. I prefer your code ...
by rickyboy
Tue May 28, 2019 7:02 pm
Forum: newLISP in the real world
Topic: Group the elements of a list
Replies: 10
Views: 1540

Re: Group the elements of a list

Right on, fdb! Lutz wins this round! :)
by rickyboy
Mon May 27, 2019 11:26 pm
Forum: newLISP in the real world
Topic: Nesting level of a list
Replies: 5
Views: 900

Re: Nesting level of a list

Excellent, fdb! Faster than mine by about a factor of 3 (on the sample input)! 2.5 times faster than the original.
by rickyboy
Mon May 27, 2019 2:52 pm
Forum: newLISP in the real world
Topic: Nesting level of a list
Replies: 5
Views: 900

Re: Nesting level of a list

Here's another way to do it. (define (nesting lst) (if (null? lst) 0 (atom? lst) 0 (+ 1 (apply max (map nesting lst))))) You be the judge if it's "better". Beware though that, although the code length is shorter, timing tests show that it is slightly *slower* than the original. map has to create mor...
by rickyboy
Mon May 13, 2019 12:18 pm
Forum: newLISP and the O.S.
Topic: Compile script to .exe with attached files
Replies: 8
Views: 3293

Re: Compile script to .exe with attached files

Hello, Just one question: Can't you combine your 3 lsp files into one? That would be the easiest way. Regards Good point, HPW. On another note, I am glad that Ralph posted his scripts which turn loads and file reads (“dynamic inclusion”) into “includes” (“static inclusion”), but only for the files ...
by rickyboy
Wed Apr 24, 2019 8:56 pm
Forum: newLISP in the real world
Topic: slice with negative "int-length"
Replies: 5
Views: 1550

Re: slice with negative "int-length"

Ah, I see what you did -- you put in the runtime checks on the bounds of the argument values. Very nice! I'd suggest commenting it a bit. I do this in my own code when I believe there is a chance that it will take me more than 5 seconds to re-parse and understand it when I return to read it in the f...