Recent posts

#1
newLISP in the real world / Re: regex-all
Last post by cameyo - June 15, 2025, 08:52:37 AM
Thanks.
You reminder me of 'collect' ... :)
#2
newLISP newS / Re: Wisp to new lisp
Last post by rrq - June 13, 2025, 09:11:43 PM
Yes I like parentheses too 8) . I remember Interlisp having square brackets as "meta parentheses" so as to avoid strings of stopping parentheses; the two forms interoperated so that ']' closed all '(' to match prior balancing '[', and likewise ')' closed all '[' to match prior balancing '('.
One could then write for example the following
(define (factorial n)
    [if (zero? n)
        1
        (* n (factorial (- n 1 ] )
Perhaps it's clearer? But the reader has to know the syntax in any case.
#3
newLISP in the real world / Re: regex-all
Last post by rrq - June 13, 2025, 06:53:48 PM
I suppose one might use find-all for that. Though, find-all doesn't provide the character index, and it doesn't provide the match overlap variant. It wouldn't be terribly hard to patch the source to make find-all offer the index (eg as $index) similar to the match count.

However, one can use collect and a small helper function to get the following alternative solution:
> (define (regex-all EXP STR OPT ALL)
  (let ((i 0)
     (move-i (fn (X) (setq i (+ (X 1) (if ALL 1 (X -1)))) X)))
      (collect (if (regex EXP STR OPT i) (move-i $it)))))

> (setq a "AAAaBAAAABcADccAAAB")
> (regex-all "[A]{3}" a 0)
(("AAA" 0 3) ("AAA" 5 3) ("AAA" 15 3))
> (regex-all "[A]{3}" a 0 true)
(("AAA" 0 3) ("AAA" 5 3) ("AAA" 6 3) ("AAA" 15 3))

EDIT: I fixed to use EXP rather than hard-coded search pattern.
#4
newLISP newS / Re: Wisp to new lisp
Last post by itistoday - June 13, 2025, 04:44:12 PM
Yeah same here, parenthesis make everything easy to understand for me, I honestly don't get why anyone hates them.
#5
newLISP in the real world / regex-all
Last post by cameyo - June 13, 2025, 07:49:32 AM
Does anyone know of any more efficient methods than the following to calculate all the matches of a regex?
Thanks.
(define (regex-all regexp str all)
"Find all occurrences of a regex in a string"
  (let ( (out '()) (idx 0) (res nil) )
    (setq res (regex regexp str 64 idx))
    (while res
      (push res out -1)
      (if all
          (setq idx (+ (res 1) 1))        ; contiguos pattern (overlap)
          (setq idx (+ (res 1) (res 2)))) ; no contiguos pattern
      (setq res (regex regexp str 64 idx)))
    out))

(setq a "AAAaBAAAABcADccAAAB")
(regex "[A]{3}" a)
;-> ("AAA" 0 3)
(regex-all "[A]{3}" a)
;-> (("AAA" 0 3) ("AAA" 5 3) ("AAA" 15 3))
(regex-all "[A]{3}" a true)
;-> (("AAA" 0 3) ("AAA" 5 3) ("AAA" 6 3) ("AAA" 15 3))
#6
newLISP newS / Re: Wisp to new lisp
Last post by cameyo - June 07, 2025, 10:36:27 AM
Interesting, but I'm fond of parentheses. :)
#7
So, what can you actually DO with newLISP? / Re: newLISP Code
Last post by itistoday - May 18, 2025, 01:20:01 PM
Nice!
#8
So, what can you actually DO with newLISP? / newLISP Code
Last post by cameyo - May 18, 2025, 10:23:30 AM
Problem Solving with newLISP
https://github.com/cameyo42/newLISP-Code
More than 3000 topics on newLISP:
- Algorithms
- Project Euler
- Rosetta Code
- Programming interview questions
- Library for recreational mathematics (344 functions)
- a lot of programming problems
#9
newLISP newS / Wisp to new lisp
Last post by fdb - March 27, 2025, 06:36:37 AM
Hi,
last week I got nerd-sniped when I saw an alternative to the 'parens-heavy' syntax of newlisp, wisp: https://www.draketo.de/software/wisp.

I've seen more alternative lisp syntaxes over the years (f.i. rhombus, shrubbery in Racket) but this is the first time that I can see this a viable alternative so I made a small newlisp module (indent.lsp) which you can download from https://github.com/luxint/wisp-newlisp.


As an example this is wisp syntax:

define : factorial n
  if : zero? n
    . 1
    * n : factorial : - n 1

which gets then transpiled into:

(define (factorial n )
  (if (zero? n)
    1
    (* n (factorial (- n 1)))))


Have fun and let me know if you like it!




#10
newLISP newS / Re: How can we get newlisp rol...
Last post by itistoday - March 20, 2025, 09:45:47 AM
I think experiments that people want to put effort into are worth trying. 👍