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

#31
This page may have the info I need.  I'll do some experiments.



http://pages.cs.wisc.edu/~rjl/landscape/">http://pages.cs.wisc.edu/~rjl/landscape/
#32
I'm using newlisp to make postscript (and thus, PDF) files for cutting things on laser cutters and CNC machines.  I love the ability to be precise and exact in my lines and angles.



For CNC cutting, I want to use plywood pieces bigger than a typical sheet of paper.  Lots of CNC software accepts PDF files where the page size is 4 feet by 8 feet, the same size as a typical sheet of plywood.



How can I specify page size using the postscript module?  If I knew how to edit the raw postscript by hand, I'd submit an updated version of postscript.lsp myself, so if someone knows how to do that in raw postscript, please post here.
#33
Quote from: "mikerudin39"2. debugging for embedded dll - no console at all...


Lutz did add an embedded DLL call that keeps the console output as normal.  I forget what he called it.  Should be in the documentation.  He added it at my request 2 years ago.  Should still be there in the API.
#34
Anything else we might add? / Re: about (directory)
July 21, 2017, 11:38:46 PM
Does that mean the non-UTF8 version of newlisp is working for you?
#35
Anything else we might add? / Re: about (directory)
July 20, 2017, 03:11:52 PM
So, the problem is his system is using code page 936 (Simplified Chinese), but newlisp is using UTF8.  To convert between encodings perhaps I need to write some bindings for libiconv, libiconv can convert between different character encodings.  But I don't see myself having time to write the bindings soon.  If he is comfortable with the C interface for newlisp modules, he can install the iconv DLL and write the bindings and that will fix the problem.
#36
Anything else we might add? / Re: about (directory)
July 20, 2017, 03:05:47 PM
Might have something to do with locale; perhaps the output of (directory) is coming in the current locale, which may NOT be UTF-8?  So, how do you convert from his locale encoding into UTF8?  What text encoding is he using if not UTF8?  Some sort of non-UTF multi-byte encoding.
#37
Anything else we might add? / Re: about (directory)
July 18, 2017, 10:32:54 AM
Can you run (set-locale) and tell us the results?
#38
Anything else we might add? / Re: about (directory)
July 16, 2017, 01:48:09 PM
To help with debugging, can you run this newlisp code and paste the results?



(define str->bytes (lambda (s) (unpack (dup "b" (length s)) s)))
(str->bytes "the real filename")
(str->bytes "the filename directory returns")


Don't  cut and paste the code; when you run str->bytes function, then put in the different strings, the one you see in Windows Explorer, and the one that (directory) returns.  Then we can compare the byte strings.
#39
Anything else we might add? / Re: and to set $it?
July 12, 2017, 09:58:46 AM
Haskell also has nice composition syntax with the "." operator, be worth studying that for some lessons.  Monads are such a big deal in Haskell, but I think a lot of JavaScript patterns are using monads and monadic style without even thinking about it.
#40
Anything else we might add? / Re: and to set $it?
July 12, 2017, 09:56:52 AM
$it has a slightly different meaning already.



But we could definitely use a "thrush" function. I was thinking, instead of two separate thrush operators -> and ->> like Clojure hash, I'd like a thrush like this:


(thrush initial-expr [idx] expr [idx] expr [idx] expr)

In this syntax, idx is an optional integer index, which thrush would use to know where in the argument list to put the previous expr in the next expr.  This gives full flexibility, without us having to change the API or do any contortions.  This works because thrus is supposed to compose functions; so if it comes across an argument that is an integer, then it knows to use it as an index.  Standard list indexing, -1 is the last item in the argument list, etc.  I think default to -1 is best, but once you set an index value, it stays the same until you set it again.


(thrush "hello" 1 printf)
(thrush "hello" 1 reverse (printf " world.")
#41
I think I found the error.  The "atan" is bombing out when drawto is called from a point, to the identical point.  So I changed my code a little to guarantee drawto isn't called when the start and end points are identical.  Now it works.
#42
newLISP Graphics & Sound / PostScript atan error
July 11, 2017, 11:08:12 PM
Hi.  On macOS Sierra, I am using postscript.lsp (newlisp 10.7.0)



In the function drawto, there is a line  newy ypos sub newx xpos sub atan neg 90 add /orient exch def


So I generate my postscript instructions with ps:render.  Then it comes time to convert the postscript file to a  PDF so I can view it, and sometimes it gives an error, other times it doesn't.  I make minor tweaks to my output code and the error goes away.  But when the error is there, it stays until I change the code, but I never figured out what change I made to avoid the error.



But anyways, I can read postscript a little, but that line doesn't make sense to me.  Why is it in there?  When I hand edit the postscript file to comment out that line, I can create the PDF without problem.



Sample code that shows the error:



(define pi (mul 4 (atan 1)))
(define (rad d) (mul d (div pi 180)))
(define (deg r) (mul r (div 180 pi)))

(module "postscript.lsp")

;; I work in inches as my base unit (72 points per inch), but scale things down
;; by scalefactor so they fit on a regular sheet of paper.

(define scalefactor 4)
(ps:scale (div 72 scalefactor) (div 72 scalefactor))

(define ¼ 0.25)
(define ½ 0.5)
(define origx (mul ½ 8.5 scalefactor))
(define origy (mul ½ 11 scalefactor))
(define my-goto (lambda (x y) (ps:goto (add x origx) (add y origy))))
(define my-drawto (lambda (x y) (ps:drawto (add x origx) (add y origy))))

;; https://math.stackexchange.com/questions/76099/polar-form-of-a-superellipse
;; answered Oct 26 2011 at 17:03 by Ross Millikan
;; polar coordinate form of a superellipse
;; r = ab/(|b cos theta|^n + |a sin theta|^n)^(1/n)
;; a is half the height
;; b is half the width
;; n is the exponent of the superellipse
(define super-ellipse-radius (lambda (a b n theta)
  (div (mul a b)
       (pow (add (pow (abs (mul b (cos theta))) n)
                 (pow (abs (mul a (sin theta))) n))
            (div n)))))

(define draw-super-ellipse (lambda (a b n)
  (letn (anglestep (rad 0.1)
         ab (mul a b)
         startr (super-ellipse-radius a b n 0)
         startx (mul startr (cos 0))
         starty (mul startr (sin 0)))
    (my-goto startx starty)
    (for (theta anglestep (mul 2 pi) anglestep)
      (let (r (super-ellipse-radius a b n theta))
        (my-drawto (mul r (cos theta)) (mul r (sin theta)))))
    (my-drawto startx starty))))

(draw-super-ellipse (mul 7 (sqrt 2)) 7 2.718)

(ps:render "standing-desk2.ps")
(! "pstopdf standing-desk2.ps")

(exit)



And here is the error when trying to open the file (macOS auto-converts it to PDF, and pstopdf also has this error:



%%[ Error: undefinedresult; OffendingCommand: atan; ErrorInfo: CharOffsets %%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
%%[ Warning: PostScript error. No PDF file produced. ] %%
pstopdf failed on file standing-desk2.ps with error code -31000
#43
Whither newLISP? / Re: (directory) nonsence
June 17, 2017, 04:31:41 PM
Quote from: "CaveGuy"I it dot'nt make ant difference still got nil. I ended up using (directory) followed with a do-list to remove everything I do not want.

thanks for the reply .



ps I missed the definitive reply before I posted this the first time ... my bad


Glad you were able to do what you wanted.  Can you try one more time.  My answer was wrong, I didn't notice the syntax error, which Lutz pointed out.  Just cut and paste this:


(directory "." "dovecot.*")
#44
Whither newLISP? / Re: (directory) nonsence
June 15, 2017, 09:14:55 PM
Quote from: "CaveGuy"first problem I put (directory) in the search box an it tells me it is too common ?



I change-dir to the directory with my log files and do a (directory) and get back a list of everything.

In this case I only want the dovecot logs so why does (directory "dovecot*") return nil ?



obviously too common a problem for search to be bothered responding with a hint.  



Its late, I'm tired, what am I overlooking ?


It is a regular expression.  What you typed, matches dovecottttttttt. Probably not your intention.  So try adding a . before the *.  Like this:


(directory "dovecot.*")
#45
Chaining them together would be easier with something like foldr or foldl from Haskell.  Lutz?  You reading this?  Also, the "thrush" operator from Clojure is pretty handy.