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

#1
newLISP in the real world / fuzzy logic
April 17, 2024, 02:06:20 AM
Luis Argüelles Méndez

A Practical Introduction
to Fuzzy Logic using LISP

Very good book!
Describes fuzzy logic using NewLisp.
#2
(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "2,07"))

result 2,069999933242798
(with comma)

(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "2.07"))

result 2

(import "libc.so.6" "strtod" "double" "char*")
(println (strtod "2,07"))

result 2,07

(import "libc.so.6" "strtod" "double" "char*")
(println (strtod "2.07"))

result 2




#3
(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "3.07"))
result = 3

With comma:
(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "3,07"))
result = 3,069999933242798


#4
oh!

#!/usr/bin/env newlisp
;; indent-newlisp.lsp
;; Author: ssqq
;; http://www.newlisp.cn
;; usage:
;; ~> newlisp indent-newlisp.lsp your-script.lsp 4 > output.lsp

(define (indent-code input-file (indent 2))
    (local (v-level new-level file-txt file-lines indent-line indent-lines)
        (setq v-level 0)
        (setq file-text (read-file input-file))
        (setq file-lines (map trim (parse file-text "\n")))
        (dolist (v-line file-lines)
            (setq new-level (get-new-level v-line v-level))
            (if (starts-with v-line ")")
                (setq indent-line (get-indent-line new-level v-line indent))
                (setq indent-line (get-indent-line v-level v-line indent))
            )
            (push indent-line indent-lines -1)
            (setq v-level new-level)
        )
        (println (join indent-lines "\n"))
    )
)

(define (get-new-level v-line v-level)
    (local (close-amount open-amount freeze-line)
        (setq freeze-str (replace {".*?[^\\]"}   v-line "" 0))
        (setq freeze-str (replace {{.*?[^\\]}}   v-line "" 0))
        (setq freeze-str (replace {\[.*?[^\\]\]} v-line "" 0))
        (setq freeze-str (replace {(?:^|\s)(?:\;|\#).*?$} v-line "" 0))
        (find-all {\(} freeze-str)
        (setq open-amount $count)
        (setq v-level (+ open-amount v-level))
        (find-all {\)} freeze-str)
        (setq close-amount $count)
        (setq v-level (- v-level close-amount))
    )
)

(define (get-indent-line v-level v-line indent)
    (let (indent-space {})
        (setq indent-space (dup " " (mul v-level (int indent))))
        (append indent-space v-line)
    )
)

(setq input-file (main-args 2))
(setq indent (main-args 3))
(indent-code input-file indent)

(exit)

This code works.
#5
It is a long time ago I was get this script.


#!/usr/bin/env newlisp
;; indent-newlisp.lsp
;; Author: ssqq
;; http://www.newlisp.cn
;; usage:
;; ~> newlisp indent-newlisp.lsp your-script.lsp 4 > output.lsp

(define (indent-code input-file (indent 2))
    (local (v-level new-level file-txt file-lines indent-line indent-lines)
        (setq out-data "")
        (setq v-level 0)
        (setq file-text (read-file input-file))
        (setq file-lines (map trim (parse file-text "\n")))
        (dolist (v-line file-lines)
            (setq new-level (get-new-level v-line v-level))
            (if (starts-with v-line ")")
                (setq indent-line (get-indent-line new-level v-line indent))
                (setq indent-line (get-indent-line v-level v-line indent))
            )
            (push indent-line indent-lines -1)
            (setq v-level new-level)
        )
        (write-file input-file (join indent-lines "\n"))
    )
)

(define (get-new-level v-line v-level)
    (local (close-amount open-amount freeze-line)
        (setq freeze-str (replace {".*?[^\\]"}  v-line "" 0))
        (setq freeze-str (replace {{.*?[^\\]}}  v-line "" 0))
        (setq freeze-str (replace {\[.*?[^\\]\]} v-line "" 0))
        (setq freeze-str (replace {(?:^|\s)(?:\;|\#).*?$} v-line "" 0))
        (find-all {\(} freeze-str)
        (setq open-amount $count)
        (setq v-level (+ open-amount v-level))
        (find-all {\)} freeze-str)
        (setq close-amount $count)
        (setq v-level (- v-level close-amount))
    )
)
(define (get-indent-line v-level v-line indent)
    (let (indent-space {})
        (setq indent-space (dup " " (mul v-level (int indent))))
        (append indent-space v-line)
    )
)

(setq input-file (main-args 2))
(setq indent 2)
(indent-code input-file indent)

(exit)
#6
newLISP in the real world / sub bug?
January 11, 2024, 07:12:11 PM
> (sub 9999999999999999,0 9999999999999998,0)
=> 2
> (- 9999999999999999 9999999999999998)
=> 1
#7
newLISP in the real world / Re: rotate bug?
January 09, 2024, 01:50:57 AM
in file nl-liststr.c replace string
if (length <= 1 || count == 0 || length == labs(count))
to
if (length <= 1 || count == 0 || length == labs(count) || count % length == 0)

and recompile NewLisp