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

#1
Quote from: "ghyll"A "submit" button on index.nhtml POSTs to script.nl. Instead of getting the desired/expected response from script.nl, I get the full text of the script file.

Quote from: "ghyll"Changing 'LOG_LEVEL to 'LOG_DEBUG resulted in malloc errors and segmentation faults, which I'm unsure how to troubleshoot. The dragonfly.log entries from these times show:



   [ERROR]: ERR: list or string expected in function find : nil
    called from user function Dragonfly:eval-template
    called from user function Dragonfly:display-file
    called from user function Dragonfly:display-view
    called from user function Dragonfly:display-error
    called from user function $error-event


Apparently, all of this trouble was not a problem with Dragonfly or the .nhtml, .html or .nl files I was using. Instead, it was somehow caused/triggered by unrelated data protection software.
#2
Quote from: "ralph.ronnquist"Maybe you overlook that directory only returns file base names, without the path prefix?


D'oh! You're completely correct. I forgot to move Terminal from my "newlisp" directory to where it should have been. Thank you :)
#3
I have a few directories full of files named with trailing spaces. I thought this would remove the trailing spaces, but it only returns nil.


(dolist (x (directory path))
        (rename-file x (trim x))
)


I tried debugging by using (trace true) with the following code:


(dolist (x (directory path))
   (file? x))
)


The "." and ".." files in the directory are files, but the other files return "nil". Does the trailing space prevent newLISP from recognizing the file as a file? Is there something else that may be causing the error (e.g. bad code on my part)? Thanks!
#4
Quote from: "itistoday"You should use the DF:log-info, DF:log-warn and DF:log-err functions to send debug statements to the dragonfly.log file (which is specified by the LOG_FILE_PATH variable in config.lsp).


Changing 'LOG_LEVEL to 'LOG_DEBUG resulted in malloc errors and segmentation faults, which I'm unsure how to troubleshoot. The dragonfly.log entries from these times show:
[ERROR]: ERR: list or string expected in function find : nil
called from user function Dragonfly:eval-template
called from user function Dragonfly:display-file
called from user function Dragonfly:display-view
called from user function Dragonfly:display-error
called from user function $error-event

with all but the first line repeated dozens of times.



I am using Dragonfly 0.72, and have made only the following changes to Dragonfly:

- route_cgi.lsp moved to /plugins-active

- (constant 'VIEW_EXTENSION ".nhtml") [line 36 of config.lsp]

- (constant 'LOG_LEVEL 'LOG_DEBUG) [line 78 of config.lsp]



I'm continuing to fiddle and troubleshoot, but of course appreciate any help figuring out what might be preventing the .nl script from running. :-)
#5
Hi Marc, thanks for the help :)  Unfortunately, the code is proprietary, so I can't take advantage of your offer to check a ZIP.



1. .nhtml is for views containing newLISP code, and .html is for views without -- just an easy way to check at a glance.

2. The .nl script is not RESTful, so I don't think it would properly translate to a resource. (Not fixing the cgi bit would also require re-writing all of the other .nl scripts as resources.)



route_cgi.lsp is loading -- I had it print something on the view (apologies for not thinking of this before I posted). The .nl script still isn't running, but I'll keep troubleshooting.
#6
tldr: How do I tell whether route_cgi.lsp is running?



A "submit" button on index.nhtml POSTs to script.nl. Instead of getting the desired/expected response from script.nl, I get the full text of the script file.



index.nhtml and script.nl are both in /views, and route_cgi.lsp is in /plugins-active... however, the same thing happened when route_cgi.lsp was in /plugins-inactive.



I got stuck trying to debug because I do not know how to verify whether route_cgi.lsp is loading/running. It doesn't show up in the network debugger (but I don't know if it should), but script.nl does.

I apologize for asking such a simple question. I have no other experience with web frameworks or cgi. I tried google, but all the answers seemed to be specific to PHP or Perl, etc.



Thank you for any help. :)
#7
Were you referring to a specific part?



Without the single quotes, the newLISP interpreter tries to evaluate the streams using implicit indexing. This doesn't work, because (for example) there is no 998th list item in `(998 (lambda () (enum-interval-descending (- 998 1) 100)))`



http://www.newlisp.org/downloads/newlisp_manual.html#implicit_rest_slice">http://www.newlisp.org/downloads/newlis ... rest_slice">http://www.newlisp.org/downloads/newlisp_manual.html#implicit_rest_slice



I''ll run through the code again to make sure all of the quotes are necessary. Thanks for the suggestion.
#8
newLISP in the real world / Re: syntax for apply
December 21, 2014, 05:32:06 PM
That makes perfect sense. Thank you for the reply (and apologies for the delayed response on my part).
#9
I'm new to programming, so I don't know how one programs in Scheme or other traditional LISP implementations.



Thanks for the help with streams! Using contexts with push/pop seems like a much easier way to manage the streams than trying to manipulate letex and expand for each function.



I'd still like to understand and master letex. I was told the error message is because I'm using letex incorrectly in my `product-stream-Reuler` function (included in my original question). It seems (from the error message) that still I don't quite understand it. I've read the manual and the wikibooks, and spent time playing around with the code, and no lightbulbs are going off. Am I using the wrong syntax? Am I using the correct syntax incorrectly? Or is that specific error message due to a problem somewhere else in my code?
#10
I assumed it was unnecessary because I was asking a syntax question, but I'm told I should post all of my code. Apologies for length and bugs.





(set 'the-empty-stream '())

(define-macro (cons-stream)
  (letex (x (args 0) y (args 1))
    (cons x (list (delay y)))
  )
)

(define-macro (delay)
  (letex (x (args 0)) (fn () x))
)

(define (head s)
  (first s)
)

(define (tail p)
  ;; (println "printing tail: " p)
  (force (last p))
)

(define (force func)
  (func)
)

(define (empty-stream? s)
  (empty? s)
)

(define (enum-interval low high)
  (if (> low high)
    the-empty-stream
    (expand (cons-stream low (enum-interval (+ low 1) high)) 'low 'high)
    )
  )

(define (enum-interval-descending high low)
  (if (> low high)
    the-empty-stream
    (expand (cons-stream high (enum-interval-descending (- high 1) low)) 'low 'high)
  )
)

(define (num-stream n)
  (expand (cons-stream n (num-stream n)) 'n)
 )

(define (filter-stream pred s)
  (cond
    ((empty-stream? s) the-empty-stream)
    ((pred (head s))
      (letex (
        a (head s)
        b pred
        c (tail s))
      (cons-stream a (filter-stream b 'c))
      ))
    (true (filter-stream pred (tail s)))
  )
)

(define (palindrome? x)
  (= x (int (reverse (string x))))
)

; untested with stream-lists
(define (biggest? x lst)
  (> x (head lst))
)


(define (accumulate combiner init-val s)
  (if (empty-stream? s)
    init-val
    (combiner (head s) (accumulate combiner init-val (tail s)))
  )
)

(define (stream-from-list lst , s)
  (setf s
    (if (empty-stream? lst)
      the-empty-stream
      (expand (cons-stream (head lst) (stream-from-list (rest 'lst))) 'lst)
    )
  )
  s
)

(define (stream-for-each func s)
  (expand
    (if (empty-stream? s)
      the-empty-stream
      (begin
        (func (head s))
        (stream-for-each func (tail s))
      )
    )
  'func 's)
)

(define (map-stream func s)
  (if (empty-stream? s)
    the-empty-stream
    (letex (
      a (func (head s))
      b func
      c (tail s))
    (cons-stream a (map-stream b 'c))
    )
  )
)

(define (print-stream s)
  (stream-for-each println s)
)

; If (= s1 s2), only returns squares
(define (product-stream s1 s2 , s3)
 (setf s3 (if
  (empty-stream? s1) the-empty-stream
  (empty-stream? s2) the-empty-stream
  (letex (
    a1 (head s1)
    a2 (head s2)
    c1 (tail s1)
    c2 (tail s2)
    )
      (cons-stream (* a1 a2) (product-stream 'c1 'c2))
      )
  ))
 s3
)

; stream of the integer 1
(setf ones (cons-stream 1 ones))

(setf x (stream-from-list '(1 2 3)) y (stream-from-list '(1 2 3)))

; stream of integers from 999 to 100
(setf a (enum-interval-descending 999 100))
(setf b (enum-interval-descending 999 100))


;aforeposted buggy draft attempt to solve Project Euler problem 4
(define (product-stream-Reuler s1 s2 , s3)
  (setf s3 (if
    (empty-stream? s1) the-empty-stream
    (empty-stream? s2) the-empty-stream
    (letex (
      a1 (head s1)
      a2 (head s2)
      c1 (tail s1)
      c2 (tail s2)
      )
      (println "a1=" 'a1 ", a2=" 'a2 "ns1=" 's1 ", s2=" 's2 "nc1=" 'c1)
      (accumulate cons '()
        (cons-stream
          ; first palindrome product of (* n s2)
          (head
            (filter-stream palindrome?
              (product-stream (num-stream 'a1) 's2)
            )
          )
          ; re-run with next n
          (product-stream-Reuler 'c1 's2)
        )
      )
    )
  ))
  s3
)
#11
newLISP in the real world / need help understanding letex
December 20, 2014, 11:14:37 PM
My code is a mess, and I apologize. I'm a newbie, and I got stuck trying to work out one of the bugs.



I'm trying to learn newLISP by solving some of the Project Euler problems. I'm currently working on Problem 4 using streams, using some functions from http://www.newlispfanclub.alh.net/forum/viewtopic.php?f=5&t=2162">//http://www.newlispfanclub.alh.net/forum/viewtopic.php?f=5&t=2162. (It's the task I was given by my mentor.)



I'm trying to use the 2nd syntax of letex, but I must have something wrong because I get "ERR: list or string expected in function empty? s2".


(define (product-stream-Reuler s1 s2 , s3)
  (setf s3 (if
    (empty-stream? s1) the-empty-stream
    (empty-stream? s2) the-empty-stream
    (letex (
      a1 (head s1)
      a2 (head s2)
      c1 (tail s1)
      c2 (tail s2)
      )
      (println "a1=" 'a1 ", a2=" 'a2 "ns1=" 's1 ", s2=" 's2 "nc1=" 'c1)
      (accumulate cons '()
        (cons-stream
          ; first palindrome product of (* n s2)
          (head
            (filter-stream palindrome?
              (product-stream (num-stream 'a1) 's2)
            )
          )
          ; re-run with next n
          (product-stream-Reuler 'c1 's2)
        )
      )
    )
  ))
  s3
)

; a and b are streams of the integers from 999 to 100
(product-stream-Reuler a b)


I've tried fully parenthasizing the initializers [i.e. `(a1 (head s1))`] and adding initializers for (a s1) and (c s2), but neither fixes the problem.



What bit of letex am I misunderstanding?



Thank you for your help.
#12
newLISP in the real world / syntax for apply
October 29, 2014, 10:26:21 PM
This code (shown below) from the "Namespace context switching" section of "http://www.newlisp.org/ExpressionEvaluation.html">Expression Evaluation in newLISP" does not seem to follow the syntax given in the manual: (apply func list [int-reduce]).



(context 'Foo)
(set 'var 123)
(define (func)
    (println "current context: " (context))
    (println "var: " var))
(context 'MAIN)

...

(apply 'Foo:func)

prints:

current context: Foo

var: 123




Is there an unlisted second syntax for apply? If not, can someone help me to understand how the above example fits (apply func list [int-reduce]) (e.g. is the second parameter also optional)?



Thanks!
#13
I think I found a typo in the pop function section of the newLISP manual.


(set 'pList '((f g) a b c "hello" d e 10))
(pop pList)  → (f g)
(pop pList)  → a
pList        → (b c "hello" d e 10)
(pop pList 3)    → d
(pop pList 100)  → 10


As-is, (pop pList 100) produces an invalid index error. The line should probably read
(pop pList 4)    → 10
or
(pop pList -1)    → 10

Is there a better place to post this? Thank you!
#14
I think I found a typo in one of the code snippets in the ref function section of the newLISP manual.


; get index vectors for list elements
(set 'pList '(a b (c d (x) e)))
(ref 'x pList)    → (2 2 0)
(ref '(x) pList)   → (2 2)
; the key expression is in a variable
(set 'p '(c d (x) e))
(ref p pList p)     → (2)


(ref p pList p)  should instead be (ref p pList)