Search found 228 matches

by ralph.ronnquist
Mon Apr 17, 2023 11:26 pm
Forum: newLISP in the real world
Topic: Search a list of values in a list
Replies: 4
Views: 456

Re: Search a list of values in a list

Ah, I misunderstood. That's slightly more convoluted. I suppose one approach could be something like the following:

Code: Select all

(filter (fn (i) (= pat (i (length pat) lst))) (flat (ref-all (pat 0) lst)))
by ralph.ronnquist
Mon Apr 17, 2023 12:25 am
Forum: newLISP in the real world
Topic: Search a list of values in a list
Replies: 4
Views: 456

Re: Search a list of values in a list

(find pat lst (fn (needles item) (member item needles))) find-all doesn't work for that though with ref/ref-all: (ref pat lst (fn (needles item) (member item needles)))) (ref-all pat lst (fn (needles item) (member item needles))) It might need "flat" on the ref-all but ref/ref-all also traverses th...
by ralph.ronnquist
Mon Apr 03, 2023 11:37 am
Forum: newLISP in the real world
Topic: return value in a function
Replies: 4
Views: 447

Re: return value in a function

Well if the return value is assigned to a variable it would be enough just mentioning that variable last. I was seeing it more in line of making the body something like the following, with your "return" function: (define (foo ..) (return (func1...) (func2 ....) ...)) The point is that for a lambda f...
by ralph.ronnquist
Sun Apr 02, 2023 11:26 pm
Forum: newLISP in the real world
Topic: return value in a function
Replies: 4
Views: 447

Re: return value in a function

yes, sometimes one wants the "prog1" function, which can be defined

Code: Select all

(define (prog1 X) X)
Without that you might do it in-line, as

Code: Select all

((fn (X) X) term1 term2 term3 ...)
or

Code: Select all

((list term1 term2 term3 ...) 0)
by ralph.ronnquist
Wed Jun 15, 2022 9:00 am
Forum: newLISP in the real world
Topic: string function
Replies: 4
Views: 1125

Re: string function

I'm confused about why you appear confuse... of course (string ""a""b"") is the same as (string "" a "" b ""); the string function packs together the stringifying of its arguments ignoring any (optional) whitespace between them. No strangeness involved afaict.
by ralph.ronnquist
Tue Mar 29, 2022 4:03 am
Forum: So, what can you actually DO with newLISP?
Topic: Cryptarithmetic
Replies: 4
Views: 1737

Re: Cryptarithmetic

.. and you should dazzle me with the code as well :)

I had a hard time avoiding brute-force, which I thought too boring, but then it started to take too much time for me so I gave up.

Ralph.
by ralph.ronnquist
Sat Jan 15, 2022 9:01 am
Forum: newLISP in the real world
Topic: Bug in struct with float arguments?
Replies: 2
Views: 1590

Re: Bug in struct with float arguments?

Yes it's a bug in the handling of the "incoming cell data" for an ffi_type_float at nl-import.c:814. That current line is floatV = (float) *(double *)&cell->aux; and should be replaced with the following floatV = (float) ((cell->type == CELL_FLOAT)? *(double *)&uint64V : uint64V); which corresponds ...
by ralph.ronnquist
Wed Dec 29, 2021 1:36 pm
Forum: newLISP newS
Topic: Error in 10.7.6
Replies: 12
Views: 4948

Re: Error in 10.7.6

My fully repeatable test is:

Code: Select all

> (push x x)
(?)
> (x 0 0)

ERR: list reference changed
> x
by ralph.ronnquist
Tue Dec 28, 2021 8:13 pm
Forum: newLISP newS
Topic: Error in 10.7.6
Replies: 12
Views: 4948

Re: Error in 10.7.6

Same behaviour in "newLISP v.10.7.5 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h"
by ralph.ronnquist
Fri Sep 10, 2021 10:25 am
Forum: newLISP in the real world
Topic: Hash-map e contexts
Replies: 5
Views: 2575

Re: Hash-map e contexts

tried to edit, to wrap the sym term into an eval, but the server doesn't let me...
by ralph.ronnquist
Fri Sep 10, 2021 10:23 am
Forum: newLISP in the real world
Topic: Hash-map e contexts
Replies: 5
Views: 2575

Re: Hash-map e contexts

1) a "hashmap" is a context without default functor, i.e.

Code: Select all

(and (context? S) (nil? (sym (term S) S nil))) 
2) using the symbol as functor results in its list if entries, i.e.

Code: Select all

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

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: 8
Views: 5248

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: 8
Views: 5248

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: 5241

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: 5241

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: 3602

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: 5241

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: 3217

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: 13326

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: 3690

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: 3690

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: 3852

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: 3469

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 ...