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

#31
@rickyboy Really really appreciate your works on my post and your valueable suggestions!!
#32
Thank you so much for your help @rickboy!! I learned a lot from you.

Based on your idea, I construct "myslice" as below:


(define (myslice xs
        idx
        (len (if (< idx 0)
   (- idx)
   (- (length xs) idx))))
 
  (if (or (>= idx (length xs)) (< idx (- (length xs))))
      (if (list? xs) '()
 (string? xs) "")

      (begin
(setq idx (if (>= idx 0) idx (+ idx (length xs))))
(if (< len 0)
   (slice xs
    (let (new-idx (+ 1 idx len)) (if (>= new-idx 0) new-idx 0))
    (let (abs-len (abs len)) (if (<= abs-len (+ 1 idx)) abs-len (+ 1 idx)))
  )
   (slice xs idx len)
   )
)
      )
  )


;; test
(setq a '(0 1 2 3 4 5))
(setq b "Hello World")
(myslice a 2) ;;->(2 3 4 5)
(myslice a 3 2) ;;->(3 4)
(myslice a 3 4) ;;->(3 4 5)
(myslice a 3 -4) ;;->(0 1 2 3)
(myslice a 3 -5) ;;->(0 1 2 3)
(myslice a 6 -2) ;;->()
(myslice a -7 2) ;;->()
(myslice a 8 -2) ;;->()
(myslice a -3 2) ;;(3 4)
(myslice a -3 -3) ;;(1 2 3)
(myslice a -3 -8) ;;(0 1 2 3)
(myslice b 4 3) ;;->"o W"
(myslice b 4 12) ;;->"o World"
(myslice b -4 -6) ;;-> "llo Wo"
(myslice b -4 -18) ;;-> "Hello Wo"
(myslice b 20 6) ;;-> ""
#33
I don't quite understand how the function slice works with negative "int-length".

The following example comes from the manual:
(slice '(a b c d e f) 2 -2)  → (c d)
As explained in manual:
QuoteIf int-length is negative, slice will take the parameter as offset counting from the end and copy up to that offset

As my view, -2 seems to point to "e"(-1 points to "f"), so why is not the result  (c d e)?



And how to design a function like this:
(myslice '(0 1 2 3 4 5) 2 -2) ->(1 2)
(myslice '(0 1 2 3 4 5) 4 -3) ->(2 3 4)
(myslice '(0 1 2 3 4 5) 4 -1) ->(4)
(myslice "newLISP" 4 -2) ->"LI"

That means the negative symbol will cause myslice select elements in opposite direction.
#34
I have a table like this:
(setq lst '(("header1" "header2" "header3") ( "11" "12" "13") ("21" "22" "23") ("31" "32" "33") ("41" "42" "43" )))

I want to get some continueous lines e.g. from the first line to the third line by this:
(filter (and (>= $idx 1) (<= $idx 3)) lst)  ;; '(( "11" "12" "13") ("21" "22" "23") ("31" "32" "33") ) wanted.

But I find the function "filter" does not support "$idx".

So, is there a better way to achieve this?
#35
Many thanks all of you for these beautiful solutions!!
#36
@fdb '(1 2) in my example means the position of elements in lst, not elements themselves. I think I give a poor example.
#37
Quote from: "newBert"Here is a solution (probably not the only one, nor the best) :
newLISP v.10.7.5 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h

> (select '(0 1 2 3 4) (difference (index true? '(0 1 2 3 4)) '(1 2)))
(0 3 4)
> ;; maybe clearer:
>
(let (lst '(0 1 2 3 4))
  (select lst (difference (index true? lst) '(1 2))))

(0 3 4)
>


If the lst contains nil(0 1 2 3 nil), how to do?
#38
newLISP in the real world / non-ascii characters in path?
December 20, 2018, 07:08:22 PM
I have the following files in a directory:

- newlisp.exe   (newlisp v10.7.4(Win64-UTF8))

- main.lsp

- 01-寻找当前目录下是否有所需文件.lsp



In the main.lsp, the first line of code is:
(load "01-寻找当前目录下是否有所需文件.lsp")

When I run "newlisp main.lsp" in this directory of console, error message given:
QuoteERR: problem accessing file in function load : "01-寻找当前目录下是否有所需文件.lsp"


My OS is win7(64), and I guess non-ascii characters in path cause this problem. But why is the newlisp v10.7.4(Win64-UTF8) not able to recognize these non-ascii charactors? And how to solve this problem?
#39
The function "select" can be used to select multi-elements of a list at one time, for example:
(select '(0 1 2 3 4) '(1 2)) ->(1 2)



Yet what I want is to get all elements other than those "selceted", that is to say, I want to obtain (0 3 4) from above example.

I tried with the function "filter" like this:
(filter (not (find $idx '(1 2))) '(0 1 2 3 4))
but it fails because "filter" does not support $idx.



So, is there a better way to anti-select elements in a list at one time by another list which assign positions those elements to be deleted?
#40
Quote from: "cameyo"(define (f converse-rate-list)
  (local (rate) (setq rate converse-rate-list))
)

I am almost sure that this is not what you are searching for...  :-)

cameyo


I'd like to have a try this. Thank you.
#41
@rickyboy What? Newlisp has a elisp style? It's a supprise!
#42
To understand the meaning of function arguments, I give there arguments long names. However, it's so boring to use these long names in function body.

I ttied like this:


(define (f converse-rate-list (define rate converse-rate) )
   body in which "rate" instead of converse-rate-list is use....)


But it fails.

Is there a better way to achievable this goal? That is to say, how to bind a symbol to a argument of function?
#43
@TedWalther

I'm very sorry. Now it does work and get the result I want.

I don't know why? Maybe I make some mistake?

newLISP-10.7.1 I use in Win7.

And many thanks for your prompt response!!
#44
newLISP in the real world / string evaculat in (if ...)
December 06, 2018, 05:04:10 PM
Here is my code:


(setq file-name-extension ".csv")
(if file-name-extension file-name-extension "")


I think the "if" expression should return a string ".csv", but I get nil.

Why is file-name-extension in the true part of the "if" expression not evaculated?