Search found 66 matches

by fdb
Wed May 12, 2021 6:04 pm
Forum: newLISP in the real world
Topic: List of indexes
Replies: 5
Views: 3361

Re: List of indexes

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 '()))
by fdb
Tue Dec 29, 2020 1:37 pm
Forum: Anything else we might add?
Topic: Manipulating byte strings -- SOLVED
Replies: 2
Views: 3915

Re: Manipulating byte strings

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!
by fdb
Wed Oct 28, 2020 9:34 pm
Forum: newLISP in the real world
Topic: Get rid of (some of) the parentheses with sublisp!
Replies: 5
Views: 5120

Re: Get rid of (some of) the parentheses with sublisp!

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)₂ (de...
by fdb
Tue Oct 27, 2020 10:24 pm
Forum: newLISP in the real world
Topic: Get rid of (some of) the parentheses with sublisp!
Replies: 5
Views: 5120

Get rid of (some of) the parentheses with sublisp!

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) (s...
by fdb
Tue Sep 29, 2020 6:29 pm
Forum: newLISP Graphics & Sound
Topic: is newlisp GS / guiserver abandoned ?
Replies: 1
Views: 3120

Re: is newlisp GS / guiserver abandoned ?

Hi , You can still download it, but as stated on http://www.newlisp.org/index.cgi?Code_Contributions The Java based GUI server shipped until newLISP v.10.7.3: http://newlisp.org/code/guiserver-1.67.tgz . It contains an editor and demo files showing how to write graphics programs using guiserver.lsp ...
by fdb
Tue Sep 01, 2020 5:45 pm
Forum: newLISP in the real world
Topic: using ref data
Replies: 5
Views: 4953

Re: using ref data

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-d...
by fdb
Sat Aug 29, 2020 5:18 pm
Forum: Whither newLISP?
Topic: "place" in the function "inc"
Replies: 5
Views: 7231

Re: "place" in the function "inc"

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 ...
by fdb
Wed Aug 26, 2020 2:30 pm
Forum: Whither newLISP?
Topic: "place" in the function "inc"
Replies: 5
Views: 7231

Re: "place" in the function "inc"

It refers to a place in a list, so you can do:

Code: Select all

> (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.
by fdb
Tue Aug 25, 2020 4:06 pm
Forum: So, what can you actually DO with newLISP?
Topic: Newlisp bindings for DuckDB
Replies: 1
Views: 3092

Re: Newlisp bindings for DuckDB

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, which shows several examples.
by fdb
Thu Aug 13, 2020 7:45 pm
Forum: newLISP in the real world
Topic: Find single number
Replies: 4
Views: 3989

Re: Find single number

Very nice! An instruction I've never used in practice.
by fdb
Wed Aug 12, 2020 6:44 am
Forum: newLISP in the real world
Topic: Find single number
Replies: 4
Views: 3989

Re: Find single number

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 i...
by fdb
Wed Aug 05, 2020 10:30 pm
Forum: So, what can you actually DO with newLISP?
Topic: Newlisp bindings for DuckDB
Replies: 1
Views: 3092

Newlisp bindings for DuckDB

Hi, I've added newLISP bindings for DuckDB at https://github.com/luxint/duckdb So what is DuckDB? Have a look at their website: 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 ...
by fdb
Thu Jul 23, 2020 7:11 pm
Forum: Whither newLISP?
Topic: where is the value which is assigned by setq to a symbol?
Replies: 4
Views: 5033

Re: where is the value which is assigned by setq to a symbol?

Wel you either do

Code: Select all

> (set 'f 100)
100
> f
100
Or you do

Code: Select all

> (setq f 100)
100
> f
100
With set you have to quote because set evaluates its arguments, setq doesn't.
by fdb
Mon Jul 13, 2020 9:23 pm
Forum: So, what can you actually DO with newLISP?
Topic: Newlisp bindings for Termbox
Replies: 0
Views: 4647

Newlisp bindings for Termbox

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 Let me know what you think or if you have any questions!
by fdb
Thu Jul 02, 2020 4:53 pm
Forum: newLISP in the real world
Topic: Sum of integers in a string
Replies: 7
Views: 5529

Re: Sum of integers in a string

Or replacing the map with a function for apply, so only traversing the string two times

Code: Select all

> (apply (fn(x y) (+ (int x) (int y))) (find-all {[1-9]\d*} "o123p0010iru5") 2) 
138
by fdb
Thu Jul 02, 2020 4:27 pm
Forum: newLISP in the real world
Topic: Sum of integers in a string
Replies: 7
Views: 5529

Re: Sum of integers in a string

Nice, I didn't know starts-with and didn't know I could use a regex in find-all, but then we could also simplify your code:

Code: Select all

> (apply + (map int (find-all {[1-9][0-9]*} "o123p010iru5")))
138
>
by fdb
Wed Jul 01, 2020 3:23 am
Forum: newLISP in the real world
Topic: Sum of integers in a string
Replies: 7
Views: 5529

Re: Sum of integers in a string

Hi cameo,

my first attempt would be:

Code: Select all

(define (parse-str str)
  (apply + (map int (clean empty? (parse str {[^0-9]} 0)))))
if it needs to be faster I would do:

Code: Select all

(define (parse-str str)
	(let (total 0)
		(dolist (s (parse str {[^0-9]} 0))
			(unless (empty? s)
				(inc total (int s))))
		total))
by fdb
Sun Nov 24, 2019 10:08 am
Forum: newLISP in the real world
Topic: Puzzle
Replies: 5
Views: 6446

Re: Puzzle

ah yes to easy when n doesn't need to be a number...

Code: Select all

(define (f n)
  (if (number? n)
		(list n)
		(- (n 0))))
by fdb
Fri Nov 22, 2019 10:21 pm
Forum: newLISP in the real world
Topic: Puzzle
Replies: 5
Views: 6446

Re: Puzzle

The simplest i could think of is:

Code: Select all

(define-macro (f n)
  (- (n 1)))
But i do not know if macro's are allowed!
by fdb
Thu Jun 06, 2019 7:51 pm
Forum: newLISP newS
Topic: newLISP language support for Visual Studio Code
Replies: 9
Views: 11092

Re: newLISP language support for Visual Studio Code

Hi cameyo,

The keybindings are in the package.json file, have you tried reloading: view/command palette/developer:reload window? If you have customised keybindings (with keybindings.json) you may have keybinding conflicts.
by fdb
Mon Jun 03, 2019 10:46 pm
Forum: newLISP newS
Topic: newLISP language support for Visual Studio Code
Replies: 9
Views: 11092

Re: newLISP language support for Visual Studio Code

Hi, I've added the ability to evaluate selected expression(s), it will either send the current selection to the REPL or, if nothing is selected, it will select the 'first' expression within the cursor position to the REPL. This 'first expression' starts 1 position left to cursor if this is a opening...
by fdb
Sun Jun 02, 2019 12:12 pm
Forum: newLISP newS
Topic: newLISP language support for Visual Studio Code
Replies: 9
Views: 11092

Re: newLISP language support for Visual Studio Code

Hi cameyo, I had added the possibility to execute the active selection in the REPL but had problems getting it to work reliable so I chose to first release without it. My way of working is that I usually test my one liners in the repl first, for multi line functions I enter them in the editor, save ...
by fdb
Sat Jun 01, 2019 8:53 pm
Forum: newLISP newS
Topic: newLISP language support for Visual Studio Code
Replies: 9
Views: 11092

newLISP language support for Visual Studio Code

I've made a GitHub repository with language support for newLISP in Visual Studio code: https://github.com/luxint/vscode-newlisp . If you don't now VS Code have a look at https://code.visualstudio.com , a very nice free editor, built on open source, from Microsoft, runs on Windows, Mac and Linux. Cur...
by fdb
Tue May 28, 2019 5:50 pm
Forum: newLISP in the real world
Topic: Group the elements of a list
Replies: 10
Views: 6457

Re: Group the elements of a list

HI, cameyo, also here you can use a standard function: explode, see below: > (setq lst (sequence 0 9)) (0 1 2 3 4 5 6 7 8 9) > (explode lst 2) ((0 1) (2 3) (4 5) (6 7) (8 9)) > (explode lst 3) ((0 1 2) (3 4 5) (6 7 8) (9)) > (setq lst (sequence 1 12)) (1 2 3 4 5 6 7 8 9 10 11 12) > (explode (explode...
by fdb
Mon May 27, 2019 9:42 pm
Forum: newLISP in the real world
Topic: Nesting level of a list
Replies: 5
Views: 3992

Re: Nesting level of a list

Not very elegant but maybe faster (for short lists I presume)

Code: Select all


(define (nesting lst prev (t 0))
	(if (= lst prev)
		t
	  (nesting (flat lst 1) lst (inc t))))


> (nesting '(a (((b c (d)))) (e) ((f)) g))
5