Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - fdb

#1
Whither newLISP? / Re: Strange behavior
April 25, 2024, 01:42:02 PM
extend is destructive, so in place extending the list. if you do not want this use append
#2
newLISP in the real world / Re: List of indexes
May 12, 2021, 11:04:59 AM
Something like below? (not very elegant, I know)


(define (index-list lst)
  (setq mylist '())
  (define (h-index-list lst agg)
    (dolist (x lst)
      (setq mv (append agg (list $idx)))
      (push mv mylist -1)
      (if (list? x)
        (h-index-list x mv)))
    mylist)
  (h-index-list lst '()))
#3
Not sure what you are trying to do here but according to the documentation around utf-8 you can use explode  : "Use explode to obtain an array of UTF-8 characters and to manipulate characters rather than bytes when a UTF-8–enabled function is unavailable".



Hope this helps!
#4
As a final  'pièce de résistance' a much better and faster convert function (down) and one to add the parentheses (up, watch the regex option/number), also file versions and of course in the sublisp syntax ! ;-)



(define (down txt)
  (replace {))+}
             txt
             (string ")" (char (+ 0x2080 (length $it)₄
             0)₂

(define (up txt)
  (replace {)[₂|₃|₄|₅|₆|₇|₈|₉]}
            txt
            (dup ")" (- (char ($it 1)₂ 0x2080)₂
            2048)₂
             
(define (down-file file)
  (write-file file
    (down (read-file file)₄

(define (up-file file)
  (write-file file
    (up (read-file file)₄


#5
I really like (new)lisp and even the parentheses but they can get kind of annoying, especially at the end of function so in a flash of insight I got the idea to replace  the right parentheses with a subscripted count if there is more then one, see below original code:

(define (initial-clauses str)
  (set 'start (array rows columns (map int (explode str))))
  (for (row 0 (sub1 rows))
    (for (col 0 (sub1 columns))
      (when (> (start row col) 0)
        (push (string (to-var row col (sub1 (start row col))) " 0")
               problem)))))

And below if run through sublisp:

(define (initial-clauses str)
  (set 'start (array rows columns (map int (explode str)₄
  (for (row 0 (sub1 rows)₂
    (for (col 0 (sub1 columns)₂
      (when (> (start row col) 0)
        (push (string (to-var row col (sub1 (start row col)₃ " 0")
               problem)₅

And the code run through itself

(define (sublisp txt)
  (set 'offset 0x2080)
  (for (x 9 2 -1)
    (replace (dup ")" x)
             txt
             (string ")" (char (+ offset x)₅
   (print (string txt)₂
   nil)


Now if someone hacks into newlisp to change this back before it gets translated you could even execute it!  ;-)
#6
Hi ,



You can still download it, but as stated on http://www.newlisp.org/index.cgi?Code_Contributions">//http://www.newlisp.org/index.cgi?Code_Contributions


Quote
The Java based GUI server shipped until newLISP v.10.7.3: http://newlisp.org/code/guiserver-1.67.tgz">//http://newlisp.org/code/guiserver-1.67.tgz . It contains an editor and demo files showing how to write graphics programs using guiserver.lsp and guiserver.jar.
#7
newLISP in the real world / Re: using ref data
September 01, 2020, 10:45:49 AM
Hi joejoe ,



the best way to get the data would be to map over the results and use implicit indexing.



So ref-all would give you a list of indices, probably the data you're looking for is one level up in this structure, then I would do:

(map (fn(x) (itunes-data (chop x))) (ref-all "Brian Eno" itunes-data))
#8
Whither newLISP? / Re: "place" in the function "inc"
August 29, 2020, 10:18:59 AM
In your example the 0 after inc in the lambda list is changed by inc.



Your lambda list says :(define (sum (x 0)) (inc 0 x))



after you do (sum 1) your lambda list is :

(define (sum (x 0)) (inc 1 x)), so the 0 has become a 1.



after you do another (sum 1) your lambda list is :

(define (sum (x 0)) (inc 2 x)), so the 1 has become a 2.
#9
Whither newLISP? / Re: "place" in the function "inc"
August 26, 2020, 07:30:05 AM
It refers to a place in a list, so you can do:

> (set 'places '(0 0 0))
(0 0 0)
> (inc (places 1))
1
> places
(0 1 0)
>


See also setq which also updates places.



The example from Code Patterns illustrates that a function is also a list (a lambda list) and you can also update that list with inc.
#10
Hi,



I've added a pivot command to the bindings, which allows for generating pivot tables (like in excel) over tables with millions of records, which is not possible in excel. Have a look at https://github.com/luxint/duckdb">//https://github.com/luxint/duckdb, which shows several examples.
#11
newLISP in the real world / Re: Find single number
August 13, 2020, 12:45:07 PM
Very nice! An instruction I've  never used in practice.
#12
newLISP in the real world / Re: Find single number
August 11, 2020, 11:44:51 PM
HI Cameyo,



I would do something like this, using a hash table:

(define (find-number lst)
(define Myhash:Myhash)  ; hash table creation, O(1) lookup time
(set ' total 0)
(dolist (n lst)
(if (Myhash n)
(dec total n)    ; decrease when already added before
(begin
(Myhash n true)
(inc total n))))  ; if not in hash table increase
(delete 'Myhash)  ; first to delete contents and namespace
(delete 'Myhash)  ; second to delete symbol
total)

(find-number '(1 2 3 4 5 3 2 1 5))

-> 4
#13
Hi,



I've added newLISP bindings for DuckDB at https://github.com/luxint/duckdb">//https://github.com/luxint/duckdb



So what is DuckDB? Have a look at their website: https://duckdb.org">//https://duckdb.org

They state that :DuckDB is an embeddable SQL OLAP database management system



In practice it is almost like SQLITE (only much faster!) so the  API I made is almost the same as the sqlite3.lsp standard module. Only exception is that BLOB's are not supported (yet) (They are in DuckDB but IMHO of little use for the expected things you would do with it).



What also doesn't work (yet) is prepared SQL statements/parameter bindings so no protection against SQL injection attacks however since this will mostly be used as a single person DB this is probably not a big issue but maybe I'll add it later, the DuckDB dynamic library supports it.



What is different from the  SQLITE module is that there is a  *very* fast CSV  import & export command, on my laptop it creates a table and imports 1.5M records within a second!



Furthermore DuckDB is a columnar database (as opposed to SQLITE which is a row based db), which means that is is *much* faster for select statements with lots of aggregations, windows functions etc. What I was also looking for is a PIVOT statement, (think about MS Excel pivot tables) but this isn't supported as it needs dynamic column creation which is only possible (AFAIK) with some dynamic SQL creation so that is what I've also created on top of this API. I haven't included this in this API but will make a separate module for that.
#14
Wel you either do

> (set 'f 100)
100
> f
100

Or you do
> (setq f 100)
100
> f
100

With set you have to quote because set evaluates its arguments, setq doesn't.
#15
Hi,



I made Newlisp bindings to the Termbox library. With these bindings you can easily create text-based user interfaces in Newlisp. You can find it at https://github.com/luxint/termbox">//https://github.com/luxint/termbox%20 Let me know what you think or if you have any questions!