Recent posts

#11
newLISP in the real world / Re: Lint and/or code formattin...
Last post by vashushpanov - February 22, 2024, 01:19:40 AM
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.
#12
newLISP in the real world / Re: Lint and/or code formattin...
Last post by dukester - February 19, 2024, 06:32:20 AM
@vashushpanov Thank you for the script! 🙏

I just tried to run your script on a file that I wanted to clean up. Sadly there was zero output.
I'm running newLISP v.10.7.5 64-bit on Linux IPv4/6 UTF-8, so maybe the regex you use in the script need to be updated? I get no error messages - just zero output!
#13
newLISP in the real world / Re: Lint and/or code formattin...
Last post by vashushpanov - February 19, 2024, 01:25:19 AM
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)
#14
newLISP in the real world / Re: Lint and/or code formattin...
Last post by dukester - February 15, 2024, 01:08:18 PM
Thx ...
#15
newLISP in the real world / Re: Lint and/or code formattin...
Last post by itistoday - February 15, 2024, 10:16:31 AM
I normally use Parinfer
#16
newLISP in the real world / Lint and/or code formatting pr...
Last post by dukester - February 15, 2024, 06:28:46 AM
Is there one hiding somewhere? I searched this Forum and the Home site w/o any luck.
#17
newLISP in the real world / Re: sub bug?
Last post by cameyo - January 17, 2024, 06:24:00 AM
From the newLISP manual:
QuotenewLISP has two types of basic arithmetic operators: integer (+ - * /) and floating point (add sub mul div).
The arithmetic functions convert their arguments into types compatible with the function's own type: integer function arguments into integers, floating point function arguments into floating points.
#18
newLISP in the real world / Re: sub bug?
Last post by cameyo - January 14, 2024, 08:44:30 AM
Some test:

(format "%.20f" (sub 9999999999999999 9999999999999998))
=> "2.00000000000000000000" (error)

(format "%.20f" (sub 999999999999999  999999999999998))
=> "1.00000000000000000000" (ok)

(format "%.20f" (sub 8888888888888889 8888888888888888))
=> "1.00000000000000000000" (ok)

(format "%.20f" (sub 1000000000000000 999999999999999))
=> "1.00000000000000000000" (ok)

(format "%.20f" (sub 10000000000000000 9999999999999999))
=> "0.00000000000000000000" (error)


(format "%.20f" (sub 10000000000000000 1))
=> "10000000000000000.00000000000000000000"

(format "%.20f" (sub 10000000000000000 2))
=> "9999999999999998.00000000000000000000"

(format "%.20f" (sub 10000000000000000 3))
=> "9999999999999996.00000000000000000000"

(format "%.20f" (sub 10000000000000000 4))
=> "9999999999999996.00000000000000000000"

(format "%.20f" (sub 10000000000000000 5))
=> "9999999999999996.00000000000000000000"

(format "%.20f" (sub 10000000000000000 6))
=> "9999999999999994.00000000000000000000"


In C++:
#include <iostream>

using namespace std;

int main()
{
    cout<<(1e16 - 1) << endl;
    cout<<(10000000000000000 - 1);
    return 0;
}
=> 1e+16
=> 9999999999999999
#19
newLISP in the real world / sub bug?
Last post by vashushpanov - January 11, 2024, 07:12:11 PM
> (sub 9999999999999999,0 9999999999999998,0)
=> 2
> (- 9999999999999999 9999999999999998)
=> 1
#20
newLISP in the real world / Re: rotate bug?
Last post by cameyo - January 09, 2024, 09:47:22 AM
Thanks!!