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

#1
newLISP newS /
April 21, 2008, 10:42:05 AM
Quote from: "Lutz"


The new behavior in 9.3.0 occurred after introducing error reporting for out of range indices on strings.




I looked on the 9.3 release notes and did not see anything related to this, or the similar new behavior on lists. Could you please direct me to an explanation of the new behavior. This change is causing many things to break in a pre-9.3 codebase that I am working from and I need a systemic way to identify all the affected functions and correct them.


Quote from: "Lutz"
So 9.3.0 behavior will stay ;-), but perhaps return 'nil' on an empty string?


I would argue that returning a nil is better than erroring out and thus requiring additional code to test if the input is within bounds (e.g. not empty) or to catch the error. It jut seems that this one could go either way, so why not default towards an implementation that results in less code.
#2
newLISP newS / char bug?
April 18, 2008, 03:56:09 PM
On version 9.3, I get the following:



newLISP v.9.3.0 on OSX UTF-8, execute 'newlisp -h' for more info.

> (char "")

string index out of bounds in function char
>


Prior to 9.3, this used to return 0. Shouldn't this be still the case being that an empty string by definition (at least in C, which I thought newLISP also followed) is one that contains only the null char ()?



Thanks,



--maq
#3
I was perusing through K+R "The C Programming Language" and came across this tidbit on bit operations:



http://www.angrypacket.com/~maq/getbits.png">



And the (p + 1 - n) doesn't make sense, as it would seem you actually want to do (p - n). I wrote the same function in newlisp both ways:



(p - n):



http://www.angrypacket.com/~maq/p-n.png">



(p + 1 - n):



http://www.angrypacket.com/~maq/p+1-n.png">



And the (p - n) is the one behaving as I would expect. What am I missing here? Am I not understanding K+R properly in their example? I couldn't imagine that this is a typo.



Any insights to clear my confusion would be greatly appreciated.



--maq
#4
Anything else we might add? /
August 04, 2005, 10:19:29 AM
Thanks Sammo. That does the trick.



--maq
#5
I have a small issue getting a regex to work the way I want it to. I set a string to the following:
(set 'command-line "woot -r 45 -w 46")
And then I want to alternate through the command line options by comparing against a list of flags that I'm looking for. Say:
(set 'opts '("r" "w"))
So I want to do the following:
(dolist (o opts)
(if (find (append "-" o "s*(w*)(s*-|$)") command-line 0)
(do-something with $1)
)
)

However I don't get a match because the append takes out the "" before the s & w. when I try to escape the "" I get "\s" or "\w", which also does not match.  So my question is, how can I escape a backlash for an append to output only a singular ""?



Thanks in advance,

--maq
#6
Anything else we might add? /
January 17, 2005, 11:03:10 PM
Thanks for the prompt reply. However, a read-buffer does not fix it. With:



(set 'in (open "foo2.png" "read"))

;;(set 'ifile (read-file "foo2.png"))

(read-buffer in 'ifile 100)

(close in)

(println "length of ifile " (length ifile))

(println "length through a get-string " (length (get-string (address ifile))))



I still get:



maq:maq $ ./test.lsp

length of ifile 90

length through a get-string 8



Interestingly though, when I use a text file I get the same length value for both. Any other thoughts?

--maq
#7
Anything else we might add? / get-string question
January 17, 2005, 10:28:02 PM
Why is it that I get different values from the following two length calls:



(set 'ifile (read-file "foo2.png"))

(println "length of ifile " (length ifile))

(println "length through a get-string " (length (get-string (address ifile))))

(exit)



--OUTPUT--

maq:maq $ ./test.lsp

length of ifile 90

length through a get-string 8



It appears that I'm truncating the string in ifile when I try to extract from a pointer with get-string. Clearly I'm missing something very basic here. Any insights would be greatly appreaciated.

thanks in advance,



--maq