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

#91
newLISP newS / core lisp functions?
March 07, 2008, 01:03:47 PM
Is there a list of newLISP functions not written in newLISP?



--hsm
#92
newLISP newS /
February 28, 2008, 11:39:00 AM
Cyril you are correct about
! I plead lack of sleep while coding ;) I've begun adding the necessary material to a .stx file for EditPlus that will do the skeleton framework for me, both the @syntax material and @example. As I use it over time I'll manage text replacement for the functions I use most. I'd move up to vi/vim except that emacs got to me first!



--hsm
#93
newLISP newS /
February 28, 2008, 09:50:38 AM
Good idea, all things being equal I have a preference for 'before a function'-- no reason really just seems right. I balance that by having the example after the function. Have you thought of adding the colorized code?



--hsm
#94
newLISP newS /
February 28, 2008, 09:21:01 AM
After all of these years I still have no idea of how to encourage documentation. Even when it is built into the language as in Perl and POD (plain old documentation) I've seen programmers unaware of what was at their fingertips. Thankfully CPAN generally has excellent documentation. One of the reasons that I switched to newLISP was precisely because of newLISPDoc. It is a mystery to me why                                                                                                             it is not used by everyone. When I finish my Chess/PGN(Portable Game Notation) module I will certainly take advantage of you hosting service as I think sharing code makes better coders of us all.



--hsm
#95
newLISP newS /
February 28, 2008, 07:43:58 AM
Ah! Trust me to trip on a typo. Yes that would certainly explain your result and bad eyesight would explain me not noticing my result!! The underscore is there because that is what is generated for each function:


<p></p><center>- &sect; -</center><p></p>

<a name="_piece"></a><h3><font color=#CC0000>piece</font></h3>
<b>syntax: (<font color=#CC0000>piece</font> <em>square</em>)</b><br/>
<b>parameter: </b><em>square</em> - which square of the board<br/>
<p><b>return: </b>the piece found at <em>square</em> of the board</p>

<p></p><b>example:</b><blockquote><pre> (piece "e1")
 => "k"</pre></blockquote>
<p></p><center>- &sect; -</center><p></p>
<a name="_side"></a><h3><font color=#CC0000>side</font></h3>
<b>syntax: (<font color=#CC0000>side</font> <em>square</em>)</b><br/>


I was just trying to take advantage of what was already generated for the index I believe.



I see your point about multiple word tags. Hadn't thought about it that way since I was only doing function names.





--hsm
#96
newLISP newS /
February 28, 2008, 06:28:53 AM
Interesting... The see-also tag works on my machine running W2k with FireFox. I didn't think to test for other combinations. The placement of the one line conversion is immediately after the similar conversion for @return. I found that otherwise all I got was @see-also as text including the value(s). I wonder what would cause what you see? And you are correct in that I had only the documented functions in mind; adding the name tag would allow jumping to blocks of text as well. Quite useful.
#97
newLISP newS / Suggested changes for newLISPDoc
February 28, 2008, 01:41:50 AM
I'd like to suggest some small changes for newLISPDoc. The are:



Remove the restrictions on <h1> - <h4>, i.e. these lines:
h1, h2, h3, h4 {
font-family: Georgia, Times New Roman, Times, serif;
    font-size: 110%;
}

Add
to the approved list:
(replace "<hr>" text "[hr]")
(replace "</hr>" text "[/hr]")

And:
(replace "[hr]" text "<hr>")
(replace "[/hr]" text "</hr>")

Then add this function:
(define (format-see-also text)
(letn (link-list (string "<b>see also: <b> - "))
(dolist (lnk (parse text))
(push (string "<A HREF="#_" lnk "">" lnk "</A>&nbsp;&nbsp;") link-list -1))
(string link-list))
)

And a corresponding line of code:
(replace ";; *@see-also (.*?)n" page (format-see-also $1) 0)


This would provide better control over headline size, horizontal rules for useful divisions and the ability to cross-reference using existing tags.



--hsm
#98
newLISP newS / Like slime?
February 24, 2008, 03:38:54 PM
Does the vi package for newLISP work like slime+vi?

How about the emacs package for newLISP?



--hsm
#99
newLISP newS /
February 22, 2008, 03:12:01 AM
Found the problem! Can't use a parameter with the same name as a function (duh!); note the use of 'side' as both. If I change either the parameter's name or the function's name then the code works as intended. Had it been a snake I'd have been dead!



Corrected looks like:
(define (find-king which-side)
(if (= which-side "w")
(setq k? white-king?)
(setq k? black-king?))
(catch
(dolist (candidate keylist)
(if (k? candidate)
(throw candidate)))))

Although I've no idea why use of a symbol as parameter should 'step' on the use of a symbol as function?



I'm into parsing chess games rather than 'playing', although the code could be the basis of such a thing. Perhaps later...
#100
newLISP newS / value expected in function??
February 21, 2008, 04:09:34 PM
I've written myself into a problem. The result after (board:find-king "w") is:


...
candidate is: f8
candidate is: f7
candidate is: f6
candidate is: f5
candidate is: f4
candidate is: f3
candidate is: f2
candidate is: f1
candidate is: e8

value expected in function = : square
called from user defined function board:white-piece?
called from user defined function board:k?
called from user defined function board:find-king


Relevant code looks like:


(define (side square)
((board square) 1))

(define (board:board key value)
  (if value
    (begin
(push key keylist)
(context 'board key value))
    (context 'board key)))

(define (white-piece? square)
(= "w" (side square)))

(define (find-king side)
(if (= side "w")
(setq k? white-king?)
(setq k? black-king?))
(catch
(dolist (candidate keylist)
(println "candidate is: " candidate)
(if (k? candidate)
(throw candidate)))))


All appears to work fine until we hit "e8" in the keylist. At that

point we get the above error message. I'm not entirely sure what it

is complaining about; that square has no value or that a function called

square was expecting a value?



Note that if I rewrite white-piece? to look like:


(define (white-piece? square)
(= "w" ((board square) 1)))


...all works fine! Efforts to trap this are problematic because it appears

to die somewhere after the call but before the body of the function!



Clues and or clue-sticks would be nice!



--hsm

p.s. I believe my addition to the default function for board solves the 'key' problem...
#101
newLISP newS /
February 21, 2008, 02:37:12 PM
Yes this is chess code. I'm converting my CPAN modules to newLISP. I use this kind of code as a learning project for languages new to me and those that I haven't used in a long time. Closest thing to this was a similar effort in scheme.



In general this comes down to parsing chess notation (algebraic at first, English is a pain in the ass so it comes later) and  doing various things with the result. Given input in PGN, I can convert to LaTeX, html, etc. Among other things I can identify the opening in various styles: tradition name, ECO, etc. Further I can extract all of the positions in a game for database use. I've even written code that uses a chess-engine's evaluation to annotate the games.



It (unlike the game itself) is all good fun!



--hsm
#102
newLISP newS /
February 20, 2008, 12:21:30 PM
The paren changes and the missing (board:init-board) were precisely the cure! Much thanks cormullion. I'd been so busy getting no where that I slipped up and left the call out!



--hsm
#103
newLISP newS /
February 20, 2008, 11:00:04 AM
So it should be:


define (init-board)
  (board "a1" (list "r" "w" "w"))
  (board "b1" (list "n" "w" "b"))
  (board "c1" (list "b" "w" "w"))
  (board "d1" (list "q" "w" "b"))
  (board "e1" (list "k" "w" "w"))
  (board "f1" (list "b" "w" "b"))
  (board "g1" (list "n" "w" "w"))
  (board "h1" (list "r" "w" "b")))


instead?



Didn't type board, that was from evaluating the file buffer...



--hsm
#104
newLISP newS / Dictionary/Hash problem
February 20, 2008, 09:17:02 AM
Given code that looks like this:


(context 'board)
(define (board:board key value)
  (if value
    (context 'board key value)
    (context 'board key)))

(define (init-board
  (board "a1" (list "r" "w" "w"))
  (board "b1" (list "n" "w" "b"))
  (board "c1" (list "b" "w" "w"))
  (board "d1" (list "q" "w" "b"))
  (board "e1" (list "k" "w" "w"))
  (board "f1" (list "b" "w" "b"))
  (board "g1" (list "n" "w" "w"))
  (board "h1" (list "r" "w" "b"))))

(context MAIN)

why do I get this:




> board
(lambda (key value)
 (if value
  (context 'board:board key value)
  (context 'board:board key)))
(lambda ((board:board "a1" (list "r" "w" "w")) (board:board "b1" (list "n" "w" "b"))
  (board:board "c1" (list "b" "w" "w"))
  (board:board "d1" (list "q" "w" "b"))
  (board:board "e1" (list "k" "w" "w"))
  (board:board "f1" (list "b" "w" "b"))
  (board:board "g1" (list "n" "w" "w"))
  (board:board "h1" (list "r" "w" "b"))))
MAIN
> (board "a1")
nil
>



--hsm