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

#421
newLISP newS /
January 15, 2008, 01:42:06 PM
I live in Miami (and sometimes Gainesville) so I could attend, I've been away on vacation the past couple of weeks so I didn't know about this "conference", but yeah, if you guys do it again I'd be happy to stop by and shoot the shit if I can. :-)
#422
newLISP newS /
December 13, 2007, 06:57:21 AM
Quote from: "cormullion"nice one Lutz!


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

> (set 'a (array 2 2 (randomize (sequence 1 10))))
((8 7) (2 10))
> (sort a)
((2 10) (8 7))


Awesome! Thanks Lutz! :D
#423
newLISP newS /
December 08, 2007, 12:05:11 AM
Quote from: "cormullion"
Quote from: "itistoday"Essentially I wrote a program in newLISP that tried its best to eliminate as many pieces as possible from a ChainShot game.


Nice project. Perhaps you could add a GUI to it one day..!


Yeah, I think I might actually, once I finish all my finals for school.  Then if there's time I might enter it into the '07 newLISP competition. :-D
#424
newLISP newS /
December 08, 2007, 12:03:26 AM
Quote from: "Fanda"I implemented a simple memory allocation hack:


Wow, that's pretty neat.  It's still doing a context-like trick by using named symbols for the pointers, and evaluating a pointer takes log(n) time (b/c of the red-black tree), but that's still a really cool trick. Thanks for sharing!


Quote from: "Fanda"Using this approach, code readability goes down to... lets say... C/C++  ;-)))


Well, almost, it's kinda difficult to make newLISP that bad. ;-)
#425
newLISP newS /
December 07, 2007, 09:44:18 AM
Quote from: "Lutz"Perhaps you are looking for is some sort of associative data access. A way to access a piece of information via a key pointing to a data-value. This is what binary-trees are used for in 99% of the cases.


Well actually the binary tree was just an example, the original tree that I had in mind was like the one I gave in the first post, where it could have an arbitrary number of children.  The main thing I wanted to be able to do was to quickly add/remove children from it.


QuotenewLISP has bult-in very fast associative data access by usage of contexts/namespaces, which internally are binary trees (the red-black kind of optiized binary tree.



Here is short chapter in the manual with examples, which might help you:



http://newlisp.org/downloads/newlisp_manual.html#hash">http://newlisp.org/downloads/newlisp_manual.html#hash



Lutz


Yeah I've read that, those are cool, but not exactly what I needed for this project.  I still think you should consider adding the 'unsafe-ref' function (or something like it). :-D
#426
newLISP newS /
December 07, 2007, 09:13:08 AM
Quote from: "cormullion"Are you thinking about speed? The need for speed...?! :)


Oh... why yes, most definitely. :)


Quote from: "cormullion"I wonder how big your lists are going to be... What's the application, out of interest?


It's for my artificial intelligence final class project.  I was originally planning on using a tree, but since I ran out of time I decided to go with a simpler method...  Essentially I wrote a program in newLISP that tried its best to eliminate as many pieces as possible from a ChainShot game.



If you haven't heard of ChainShot, and you have a Mac, you can download a free version of it here: http://www.wonderwarp.com/otis/">//http://www.wonderwarp.com/otis/.  Here's a screenshot of a typical board mid-game:



http://www.kinostudios.com/images/otis.jpg">



The game works like this: the player clicks on blocks, and if the block that they click on has any pieces around it (above, below, left or right) that are of the same color, then all of the pieces that are adjacent to those and are the same color will be eliminated (including the block that was clicked on).  Then any pieces above those will fall down, and if an entire column is eliminated then any columns to the right of that will be slid over to the left to eliminate all gaps.  The game ends when there are no possible moves left.



As you can imagine (if I had time to go with the tree version of the algorithm) the tree would get really big for a 20x20 board.  As it turned out I wasn't able to do that because I didn't know how to do that quickly in newLISP, and because I came up with an alternate algorithm that was faster to implement and worked pretty well to boot.  I also made it multi-"threaded" using newLISP's 'fork' function.  :)



Usually it did a pretty darn good job of solving them in a reasonable amount of time (under a minute), especially if the boards were less than size 20x20.
#427
newLISP newS /
December 07, 2007, 07:59:09 AM
Is it possible for there to be a hypothetical built-in function called 'unsafe-ref' that returned an internal reference (pointer) to something?  Then you'd be able to do things like this without having to walk down the tree/list twice (once to find the indices, and once again for nth-set to follow them back down to update the node).  It would also add greater flexibility to what newLISP could do I think... at the cost of potential crashes. :-p
#428
newLISP newS /
December 07, 2007, 07:49:27 AM
Thank you both!  Using 'ref' and 'nth-set', that's what I was looking for!  Coming from far-away lands that always had references, I'm not used to this method of mutably modifying things.



Thanks again!
#429
newLISP newS /
December 06, 2007, 06:49:49 PM
OK, I fixed the problem, the code had a bug in the indexing, it should be:


(define (TREE-label tree) (tree 1))
(define (TREE-left tree) (tree 2))
(define (TREE-right tree) (tree 3))
(define (set-TREE-label tree value)
  (nth-set (tree 1) value))


And also, I was right, this method does not allow you to easily modify the data inside the tree... Here's an example of what I want to do:


(set 'my-tree (make-depth-3-binary-tree))
(set-TREE-label (find-subtree my-tree 3) 2000)

(println "3: " (find-subtree my-tree 3))
(println "2000: " (find-subtree my-tree 2000))


I want that to print:


3: nil
2000: (labeled-binary-tree 2000 () ())


But instead it does the opposite because nothing was changed.  So my question is ... how do you do this in newLISP without jumping through crazy hoops or copying large amounts of data?  Or similarly, as I asked in the first post, how do you add children to an already existing tree without copying the entire thing or generating a million contexts? (and with those you've got to deal with the overhead of newLISP's red-black tree for symbol lookup).
#430
newLISP newS /
December 06, 2007, 06:26:36 PM
Thanks for your replies and the binary tree example, but I'm still worried that it won't work the way I want.  For example, what will this do:


(set-TREE-label (find-subtree tree 5) 2000)

Will that update what's in the tree itself, or will that only update a copy of what was in the tree?





Edit: I'm trying to test this on my own but I'm getting nil ... e.g. this prints out nil:


(set 'my-tree (make-depth-3-binary-tree))
(println (find-subtree my-tree 3))


(I fixed the problem, see below)
#431
Anything else we might add? /
December 06, 2007, 03:21:29 PM
Quote from: "newdep"My second contribution is (although still in progress)

(load "http://www.nodep.nl/downloads/newlisp/nlist.lsp">//http://www.nodep.nl/downloads/newlisp/nlist.lsp")


Wow, I just spent some time using that to go through the newLISP files on your server, they're amazing!  My favorite has to be worm.lsp!



Great job! :-D



And I love how you can load them just by using them as an argument to newlisp:


$ newlisp http://www.nodep.nl/downloads/newlisp/worm.lsp
#432
newLISP newS /
December 06, 2007, 01:12:32 PM
On a similar note, how would one implement something like a binary search tree in newLISP without having to generate named contexts?  It doesn't seem ... possible.
#433
newLISP newS / Re: (length my-list) - O(n) or O(1) ?
December 04, 2007, 02:07:12 PM
Quote from: "Cyril"Oops! Wrong! It's O(n)! Very, very evil typo. Sorry, folks. And nobody have corrected me. :-(


Are you saying that's what I get for trusting you? ;)



Yeah.  That's a problem I think...  Lutz?
#434
Anything else we might add? /
December 04, 2007, 07:04:20 AM
Quote from: "cormullion"However, none of the newLISP users from this forum are into IRC, so the channel has been quiet for most of the year.


Ah, oh well.  It's just nice sometimes when you're a newLISPnewBIE and have a question that needs a quick answer.


QuoteBut if you like talking to yourself, it's kind of fun... :)


I might take you up on that. ;-)
#435
newLISP newS /
December 04, 2007, 07:01:32 AM
Thanks guys!


Quote from: "Lutz"For 'last' the optimization was never done, but is trivial to add for 9.2.9.


That would be just hunky-dory! :-D