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 - Tim Johnson

#31
From my previous programming experience, I've had many needs for the index of a search result.

I'm aware that in newlisp one takes more of a functional approach, but it seems to me

that the execution of 'assoc in the native C code would have some sort of offset recorded, thus

it would be an additional (and valuable) resource to have the offset (index) provided in a system variable.

The specific case that prompts me to ask this question is where I would have an "associative" list whose

members would need to be

1)accessed

2)Any number of possible logical branches executed based on the contents of the member.

3)changed

I've written this:

;; With 'all, return indexes for all occurances of 'key in 'lst. Without 'all return the index of the first occurance.
(define (getAssocPos key lst all)
(letn((cmp (fn(x) (= (x 0) key)))
(res (index cmp lst)))
(if (empty? res)
nil
(if all
res
(first res)))))

Thus (I think) getAssocPos will allow me to retrieve, then store an offset/index which will reference a member-list

and then allow me to easily reset it in the outer list via 'setf.

I hope this answers your question.

Thanks for the 'find example. I have use for that.

cheers

tim
#32
From the manual
(assoc 1 '((3 4) (1 2)))  → (1 2)

Is there a system variable that stores the index/position of '(1 2)?

And if not,

1)What is the best way to get the index?

2):) Put it on _my_ wish list.

thanks

tim
#33
Example follows. First the data structure that "drives it"
set form-data [
"txDBS"[type "select" txt[llabel "Muni:" lj 1] atr[data [(munis)] choice (muni) size 4]]
"apn" [type "text" txt[llabel "Enter Apn:" lj 1] atr[value (any[apn ""]) size 20 maxlength 20 req[(if not mu/get 'apns)]]
"apns"[type "select" txt[llabel "OR - Choose APN:" lj 1] atr[data [(*apns*)] size (apn-size)]]
"submit" [type "submit" txt[llabel ""] atr[value "Next =>"]]
"reset" [type "reset" txt[llabel ""] atr[value "Reset"]]
"task" [type "hidden" txt[] atr[value (cgi/get 'task)]]
"subtask" [type "hidden" txt[] atr[value "save"]]
]

To translate to newlisp think thusly: Insert 'eval after a opening paren. Convert opening braces to opening parens, closing braces to closing parens

We see that datastructure can contain code also, in the case of the 'req value for key "apn"

Now the 'mu "context" 'loads the data structure
mu/load form-data ;; the forward slash is 'something' like the colon in newlisp

Now we render the data structure:
print htm[
form/action/method (path) "POST"[
table[
tr[td/align "right"[(mu/pop-label "apn")]
  td/align "left"[(mu/render "apn")]]
tr[td/align "right"[(mu/pop-label "txDBS")]
  td/align "left"[(mu/render "txDBS")]]
(apn-list)
tr[td/align "right"[(mu/render "submit")]
  td/align "left"[(mu/render "reset")]]]
(mu/render "task")(mu/render "subtask")]]

So far, everything from rebol seems translate well to newlisp.

Data drives it.

Go Saints.
#34
What I would like to comment on is not meant to add to or detract from any of conversations going on in this thread,

but consider my observations to be parallel to the topic:



Oftentimes, it appears to me that the concept of OOP becomes a sort of benchmark with which one system or programming

language is measured against another. My experience has been is that OOP is a paradigm, and one of many. A slightly different

perspective was given to me by one of my nieces, also a programmer, who at one time worked for Carl Sassenrath, the developer

of rebol and before that - the amiga operating system. According to her, Carl was fond of saying:
QuoteData drives it!


I refer also to "The Pragmatic Programmer" by Hunt & Thomas and their chapter on Metaprogramming and Metadata. This is

is further impressed on me when I recall my days working with Microsoft Access and it's Property List Driven interfaces.



Python is very strictly engineered and very OOP in nature, yet, it has occurred to me as programmer who usually working on a Code Base alone,

(I often work on multi-programmer projects but individuals work on their own codebase) that perhaps a data-driven paradigm needs

as much of a look as the OOP approach. Indeed, both rebol and newlisp can introspect and manipulate symbols, can use data and code

interchangeably in a way that python does not do. This is why as I learn newlisp, I shall focus more on the functional and list processing

aspects.



And that is why - although I am very interested in newlisp's progress towards OOP/FOOP - I will begin by looking at the list processing and

the functional aspects. Whether passed by reference or not. :)
#35
Quote from: "Lutz"If you want to pass by reference, you also can use the new FOOP (since development version 10.1.8) as defined here: http://www.newlisp.org/downloads/development/newLISP-10.2-Release.html">http://www.newlisp.org/downloads/develo ... lease.html">http://www.newlisp.org/downloads/development/newLISP-10.2-Release.html and stable in current development version 10.1.10.

Thank you Lutz. I will lay low for a while and try to to digest all of this.
#36
Kazimir:

The fix is really quite easy. The code becomes
(define (set-pair lst key val)
(unless(set-ref (list key '?) (eval lst) (list key val) match)
(push (list key val) (eval lst) -1)))

And the call becomes (set-pair 'attrs attr value)  ;; no 'set!
Note the use of (eval lst) in the function body and the quoting of the argument in the call.

But the peripheral discussion is of great value to me. Thank you for the code examples

and especially the explanation.

After having my coffee, I realize that question 2) was really not a question, but suffice it

to say, that coming from python, the associative structure of dictionary is quite handy, but

the b-tree nature of the internals makes ordering impossible with the native dict, although derivative

classes with ordering can (and are) created.



I think it would be great if 'set-pair were a native (written in C) newlisp function, but that is just me.

thanks again

tim (finishing-my-coffee 'mug)
#37
Here's the sample code:
(println "<pre>")
(define (set-pair lst key val)  ;; set a pair if found or add it if not found
(unless(set-ref (list key '?) lst (list key val) match)
(push (list key val) attrs -1)))
(set 'attrs '(("ID" "form0") ("method" "POST") ("name" "form0") ("action" "[[action]]")   ;; sample target list
("onsubmit" "return checkLoginForm(this);")))
(println "Original List:")
(println attrs)
(set 'attr "action")  ;; existing key
(set 'value "mycgiscript.lsp")  ;; new value
(set 'attrs(set-pair attrs attr value))  ;; call the function
(println "nList Pair Modified:")
(println attrs)   ;; test the result
(set 'attr "newaction")  ;; non-existing (new) key
(set 'value "make weave not lore")  ;; value for key
(set 'attrs(set-pair attrs attr value))  ;; call it
(println "nList Pair Added:")           ;; display results
(println attrs)


Now, here are the results:
Original List:
(("ID" "form0") ("method" "POST") ("name" "form0") ("action" "[[action]]") ("onsubmit"
  "return checkLoginForm(this);"))

List Pair Modified:
(("ID" "form0") ("method" "POST") ("name" "form0") ("action" "mycgiscript.lsp") (
  "onsubmit" "return checkLoginForm(this);"))

List Pair Added:
(("ID" "form0") ("method" "POST") ("name" "form0") ("action" "mycgiscript.lsp") (
  "onsubmit" "return checkLoginForm(this);")
 ("newaction" "make weave not lore"))

And it works just like I want it to, but three questions evolve from this exercise:

1)How can I pass the 'lst argument by reference so that the 'set-pair function becomes destructive?

Example: (set-pair attrs attr value) ;; => 'attrs is changed with calling 'set
2)I come from a background (most recently) in python and rebol, both which pass variables

by reference.

3)I don't believe that Lutz does anything for no good reason:

Why do  most newlisp functions pass arguments by value?

Thanks

tim
#38
I consider it very important that I be able to install and run newlisp from /usr/local. And in my experience,

many sysadmins for remote servers wouldn't have it any other way.

Here is what I did on my system, it is a bit of a hack and I would invite information on a cleaner way to do

it.

at line 522 in newlisp.c, changedresult = setenv("NEWLISPDIR", "/usr/share/newlisp", TRUE);
to result = setenv("NEWLISPDIR", "/usr/local/share/newlisp", TRUE);
And prior to compiling:

NEWLISPDIR=/usr/local/share/newlisp

And I have a complete install in /usr/local/bin, /usr/local/share/newlisp.

But this is a bit of a hack...

thanks

 tim
#39
consider the following code block in Makefile
NOTE when changing PREFIX, then newlisp should only run
# run in an environment, where NEWLISPDIR is predefined,
# else NEWLISPDIR will be defined during newlisp startup
# as /usr/share/newlisp which is hardcoded in newlisp.c
prefix=/usr
datadir=$(prefix)/share
bindir=$(prefix)/bin
mandir=$(prefix)/share/man

I'm not entirely clear what the comments mean. But will it suffice to

change prefix to /usr/local?

or

make --prefix=/usr/local install
#40
You were right Ted. No changes were necessary. Just curious:

What did you do differently with the shell script on configure-alt?



Also, I could probably figure this out myself, but perhaps we can share with

the community how to target newlisp for installation under /usr/local.

The reason for this is that on many *nix systems, /usr/local is used

for user installed binary and their systems and many tarball installations,

like mutt for instance automatically install to /usr/local/bin, /usr/local/share

etc. Many linux installations (mine included) put /usr/local on a separate

partition. This enables upgrading the OS without wiping the user installed

stuff.



thanks

tim
#41
Heh. Heh. Walked away from the computer. Poured myself a glass of my good old homebrew.

Came back, commented out the the line about debian and uncommented the line about

slack.

Flawless install followed.

cheers

tim
#42
Here is the output from configure
bash-3.1$ ./configure

removing old objects and setting correct permissions ...
discovering platform and default memory model ...

detected memory model ILP32
detected Operating System LINUX
creating makefile_configure ...

to make for ILP32 on LINUX type:
    make
to make for any other system do:
    make -f makefile_xxx
where makefile_xxx is one of the preconfigured makefiles

What I infer from the above is that all I need to do is invoke "make"

Now here is the output from make:
bash-3.1$ make
make -f makefile_configure
make[1]: Entering directory `/home/tim/downloads/install/newlisp-10.1.7'
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX newlisp.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-symbol.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-math.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-list.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-liststr.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-string.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-filesys.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-sock.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-import.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-xml.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-web.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-matrix.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-debug.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX nl-utf8.c
gcc -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX pcre.c
gcc newlisp.o nl-symbol.o nl-math.o nl-list.o nl-liststr.o nl-string.o nl-filesys.o nl-sock.o nl-import.o nl-xml.o nl-web.o nl-matrix.o nl-debug.o nl-utf8.o pcre.o -m32 -g -lm -ldl -lreadline -o newlisp # for UBUNTU Debian
/usr/lib/gcc/i486-slackware-linux/4.3.3/../../../libreadline.so: undefined reference to `PC'
/usr/lib/gcc/i486-slackware-linux/4.3.3/../../../libreadline.so: undefined reference to `tgetflag'
/usr/lib/gcc/i486-slackware-linux/4.3.3/../../../libreadline.so: undefined reference to `tgetent'
/usr/lib/gcc/i486-slackware-linux/4.3.3/../../../libreadline.so: undefined reference to `UP'
/usr/lib/gcc/i486-slackware-linux/4.3.3/../../../libreadline.so: undefined reference to `tputs'
/usr/lib/gcc/i486-slackware-linux/4.3.3/../../../libreadline.so: undefined reference to `tgoto'
/usr/lib/gcc/i486-slackware-linux/4.3.3/../../../libreadline.so: undefined reference to `tgetnum'
/usr/lib/gcc/i486-slackware-linux/4.3.3/../../../libreadline.so: undefined reference to `BC'
/usr/lib/gcc/i486-slackware-linux/4.3.3/../../../libreadline.so: undefined reference to `tgetstr'
collect2: ld returned 1 exit status
make[1]: *** [default] Error 1
make[1]: Leaving directory `/home/tim/downloads/install/newlisp-10.1.7'
make: *** [default] Error 2

 Following is the text of the automatically generated make_configure:

# makefile for newLISP v.10.x.x on LINUX with readline and UTF-8 support
#
# Note, that readline support may require different libraries on different OSs
#

OBJS = newlisp.o nl-symbol.o nl-math.o nl-list.o nl-liststr.o nl-string.o nl-filesys.o
    nl-sock.o nl-import.o nl-xml.o nl-web.o nl-matrix.o nl-debug.o nl-utf8.o pcre.o

CFLAGS = -m32 -Wall -pedantic -Wno-strict-aliasing -Wno-long-long -c -O2 -g -DREADLINE -DSUPPORT_UTF8 -DLINUX

CC = gcc

default: $(OBJS)
    $(CC) $(OBJS) -m32 -g -lm -ldl -lreadline -o newlisp # for UBUNTU Debian
#   $(CC) $(OBJS) -m32 -g -lm -ldl -lreadline -ltermcap -o newlisp # slackware
#   $(CC) $(OBJS) -m32 -g -lm -ldl -lreadline -lncurses -o newlisp # other Linux Dist
#   $(CC) $(OBJS) -m32 -g -lm -ldl -o newlisp # without readline support
    strip newlisp

.c.o:
    $(CC) $(CFLAGS) $<

$(OBJS): primes.h protos.h makefile_linux_utf8

Perhaps the line referenced by the comment: "# for UBUNTU Debian" might be the problem,

because this is not not ubuntu debian.
#43
Quote from: "cormullion"I don't think you're reflecting the pattern of the target list precisely enough.  This might work:


(match '(("ID" ?) *) attrs true)

That's correct. Thanks.
#44
cormullion does it again. Here were have cut the LOC in half:

(unless(set-ref '("action" ?) attrs (list "action" newaction) match)
  (push (list "action" newaction) attrs -1))

But this raises a couple of more questions. Obviously the functor argument
match does its job here, but I'm trying to use 'match as standalone

and not getting the results I want:
> (set 'attrs '(("ID" "form0") ("method" "POST") ("name" "form0")))
(("ID" "form0") ("method" "POST") ("name" "form0"))
> (match '("ID" ?) attrs)
nil

What am I doing wrong?

thanks

tim
#45
Quote from: "cormullion"How about:


(set-ref  '("action" ?) l '("action" "http://localhost/cgi-bin/test.lsp") match)

Gotta try this. I will get back to you folks on it.

Thanks very much.

tim