Search found 216 matches

by ralph.ronnquist
Sun Nov 24, 2019 10:03 am
Forum: newLISP in the real world
Topic: Puzzle
Replies: 5
Views: 2248

Re: Puzzle

Yes, quite challenging. Especially with the (implied) constraint that f is restricted to integers, as arguments and values (otherwise it's all too easy). Perhaps the following is acceptable? (define (f n) (if (= n) 0 (> n) (if (odd? n) (inc n) (- (dec n))) (if (odd? n) (dec n) (- (inc n)))))
by ralph.ronnquist
Wed Nov 20, 2019 9:38 pm
Forum: newLISP in the real world
Topic: Fractran language
Replies: 4
Views: 1187

Re: Fractran language

Ah. I didn't think about that. One might make a bitsL function for that, eg: ; Compute "bits" for bigint and int (constant 'MAXINT (pow 2 62)) (define (prep s) (string (dup "0" (- 62 (length s))) s)) (define (bitsL n) (if (<= n MAXINT) (bits (int n)) (string (bitsL (/ n MAXINT)) (prep (bits (int (% ...
by ralph.ronnquist
Wed Nov 20, 2019 6:21 am
Forum: newLISP in the real world
Topic: Fractran language
Replies: 4
Views: 1187

Re: Fractran language

Interesting. To gain speed, you could specialize the power-of-2 test into the following (nil? (find "1" (1 (bits n)))) That method is 1-2 magnitudes faster than "proper math's", and using bits for ilog2 as well, it could become the following, faster run function: (define (run2 program start step) (d...
by ralph.ronnquist
Mon Oct 28, 2019 4:49 am
Forum: newLISP in the real world
Topic: nL cron script
Replies: 6
Views: 1096

Re: nL cron script

println ? did you mean string ?

btw, cron scripts are run in $HOME so it would append to $HOME/ltcbtc.txt
by ralph.ronnquist
Mon Oct 28, 2019 2:42 am
Forum: newLISP in the real world
Topic: nL cron script
Replies: 6
Views: 1096

Re: nL cron script

A script file needs to tell which interpreter to use at it's first line, so it'd be like #!/usr/local/bin/newlisp (append-file "ltcbtc.txt" (println pairs (date (date-value) 0 "%y%m%d%H%M%S"))) if you have installed newlisp at there. Alternatively you make an embedded executable with the script; som...
by ralph.ronnquist
Sat Oct 26, 2019 10:59 pm
Forum: newLISP in the real world
Topic: newLISP at the University of Utah
Replies: 2
Views: 914

Re: newLISP at the University of Utah

Nice! Though they should probably review the "Case expressions" section.
by ralph.ronnquist
Sat Oct 26, 2019 10:54 pm
Forum: newLISP in the real world
Topic: nL cron script
Replies: 6
Views: 1096

Re: nL cron script

* * * * * joe /home/joe/winny/winny.lsp A line like the above would be fine in /etc/crontab or in /etc/cron.d/something-or-other , but for a user's crontab line ( crontab -e ), you'd skip the "user" field: * * * * * /home/joe/winny/winny.lsp It's of course all nicely documented in $ man cron hth
by ralph.ronnquist
Sun Oct 13, 2019 2:28 am
Forum: newLISP in the real world
Topic: translating big numbers
Replies: 2
Views: 752

Re: translating big numbers

There is the interesting issue of "precision" in this, i.e. how precises the decimal representation is realative to the actual numberical value held. For example, you might define the following functions: (define (digits n) (let (x 0 m 1) (while (!= n (add n m)) (inc x) (setf m (div m 10))) x)) (def...
by ralph.ronnquist
Thu Sep 19, 2019 8:06 am
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 2695

Re: Timing function problem

Most likely it's the define in define , which probably ends up growing the symbol table for each new define in some way. You could compare with making it a heap based temporary function instead: (define (merge lstA lstB op) (let ((ciclo (fn (out lstA lstB) (cond ((null? lstA) (extend (reverse out) l...
by ralph.ronnquist
Sun Sep 01, 2019 1:35 am
Forum: newLISP in the real world
Topic: Twin primes
Replies: 3
Views: 969

Re: Twin primes

You will gain a bit in speed for handling larger numbers by checking if the modulus of a prime product include any of the product primes. The code could be something like the following: (define (pairs-i1 a b) (let ((out (list)) (x nil) (FX (* 2 3 5 7 11 13)) (M 0)) (for (y (if (odd? a) a (inc a)) b ...
by ralph.ronnquist
Fri Aug 30, 2019 7:11 am
Forum: newLISP in the real world
Topic: Twin primes
Replies: 3
Views: 969

Re: Twin primes

Something like this, perhaps:

Code: Select all

(define (pairs-i a b)
  (let ((out (list)) (x nil))
    (for (y (if (odd? a) a (inc a)) b 2)
      (if (1 (factor y)) (setf y nil) x (push (list x y) out -1))
      (setf x y))
    out))
by ralph.ronnquist
Mon Aug 26, 2019 3:57 am
Forum: newLISP in the real world
Topic: Create polynomials
Replies: 3
Views: 973

Re: Create polynomials

I'm not sure about "better/more elegant", but it's always fun and interesting to explore alternative newlisp articulations. I rendered this one, as an iterative though rather functional in style, "hiding" the iteration in a map primitive: (define (make-poly coeff) (let ((rank (length coeff)) (polyte...
by ralph.ronnquist
Tue Aug 06, 2019 12:56 pm
Forum: newLISP in the real world
Topic: Web app server
Replies: 3
Views: 949

Re: Web app server

As I remember, ranwar.tgz is an attempt to implement a front-end in newlisp to allow concurrent request handling, and "emulate" persistence for newlisp app scripts by means of the shared memory facility. It starts a sub process for every request, and is designed for a notion "app instance" by means ...
by ralph.ronnquist
Tue Aug 06, 2019 11:21 am
Forum: newLISP in the real world
Topic: Web app server
Replies: 3
Views: 949

Re: Web app server

Can newLISP be used to create a standalone http web app server? The answer to that one is of course "yes"; newlisp, with -http, provides a basic HTTP server for a small range of file types, including ".cgi" which it handles in a similar way to apache2. I.e., the ".cgi" file is an executable, and po...
by ralph.ronnquist
Sat Jun 22, 2019 2:22 am
Forum: newLISP and the O.S.
Topic: Compile script to .exe with attached files
Replies: 8
Views: 3741

Re: Compile script to .exe with attached files

Well, as always, the first thing to exclude is "operator error". I don't know what the prevalent mistakes might be for Windows, but at least you should confirm that the program runs without being packed into a single executable. I.e., if the program is in the scripts A.lsp , B.lsp and C.lsp , with A...
by ralph.ronnquist
Mon Jun 17, 2019 9:49 pm
Forum: newLISP in the real world
Topic: loading html templates
Replies: 2
Views: 940

Re: loading html templates

If that printing happens from a CGI script for newlisp in -html operation, then it'd be explained as an API misunderstanding. newlisp in -html mode is quite forgiving about the CGI response, but it treats anything before the first empty line as the HTTP headers part, and that following the first emp...
by ralph.ronnquist
Mon Jun 17, 2019 1:20 pm
Forum: newLISP in the real world
Topic: initializer expressions by a predefined list in "let"
Replies: 3
Views: 1040

Re: initializer expressions by a predefined list in "let"

The use of single symbol is not a documented syntax form , and generally, that second element of the let term is not evaluated but processed as is (and only evaluated in parts). So that syntax form is a DIY opportunity :) For a once-off need, I'd wrap it into a letex , as in the following. (letex (l...
by ralph.ronnquist
Sat Jun 15, 2019 11:56 pm
Forum: newLISP in the real world
Topic: format json-parse data into html
Replies: 7
Views: 1658

Re: format json-parse data into html

If you read first argument to format very carefully a few times, you will eventually discover the missing back-quote. :)
by ralph.ronnquist
Sat Jun 15, 2019 12:56 am
Forum: newLISP in the real world
Topic: format json-parse data into html
Replies: 7
Views: 1658

Re: format json-parse data into html

Yes, I kind of thought that jsondata was the whole thing. Since you have (set 'jsondata (lookup "products" (lookup "result" alie))) it'll already have gone into the "products" value part, and therefore my suggested ref of a ("product" ?) pair in jsondata isn't much good. As you noticed :) If jsondat...
by ralph.ronnquist
Mon Jun 10, 2019 7:07 am
Forum: newLISP in the real world
Topic: format json-parse data into html
Replies: 7
Views: 1658

Re: format json-parse data into html

You may want to build around using ref and ref-all , to "pick raisins"; something like this perhaps: (define (raisins jsonitem) (format "<a href=\"%s\">%s</a>\n"<img src=\"%s\">\n\n" (string (if (ref '("productUrl" ?) jsonitem match true) ($it 1))) (string (if (ref '("imageTitle" ?) jsonitem match t...
by ralph.ronnquist
Wed Jun 05, 2019 12:43 pm
Forum: newLISP in the real world
Topic: Primitive "case" does not work
Replies: 3
Views: 975

Re: Primitive "case" does not work

I suppose it links back to how the case term works in other Lisp variations.

There are also other conditional term forms such as if and cond to fill the need. Perhaps the prior question would be to ponder why having a case term at all.
by ralph.ronnquist
Wed Jun 05, 2019 9:37 am
Forum: newLISP in the real world
Topic: Primitive "case" does not work
Replies: 3
Views: 975

Re: Primitive "case" does not work

Yes, as you know, the case term does not evaluate the branch keys, so you'll have to resort to a letex embedding, as in

Code: Select all

(define (f obj a da b db)
  (letex ((a a) (b b))
      (case obj
          (a da)
          (b db)
          (true obj)
   )))
by ralph.ronnquist
Fri May 31, 2019 2:55 am
Forum: newLISP in the real world
Topic: Maximum Product Sublist
Replies: 5
Views: 1209

Re: Maximum Product Sublist

Indeed, sublist was a quite fun exercise. Thanks :) I ended up with the following as my "best" candidate: (define (sublists s (i 0) (n (inc (length s))) (N n)) (collect (if (> n 2) (i (dec n) s) (> (setf n (dec N)) 2) ((inc i) (dec n) s)))) That one performed best for me, and (more or less incidenta...
by ralph.ronnquist
Thu May 30, 2019 11:29 am
Forum: newLISP in the real world
Topic: Group the elements of a list
Replies: 10
Views: 1897

Re: Group the elements of a list

Thanks. Yes, as you say, the trans function really treats its input list s as a collection of equivalence classes, and combines those that overlap into the smallest collection of classes. The similar function for non-reflexive relations (or directed arcs) would rather concern transitive reachability...
by ralph.ronnquist
Wed May 29, 2019 8:51 am
Forum: newLISP in the real world
Topic: Group the elements of a list
Replies: 10
Views: 1897

Re: Group the elements of a list

How about "transitive closure", then? I.e. given a list of pairs that notionally would, say, represent links in a graph, determine the lists of transitively connected "nodes", or in other words, join all sub-lists that share some element (transitively). A recursive solution could be something like t...