Lutz, is it intentional that (read-key true) returns 0 instead of nil when there is no keypress to report?
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
newy ypos sub newx xpos sub atan neg 90 add /orient exch def
(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)
%%[ 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
(context '/dev/urandom)
(define max-32bit-int 4294967295)
(define fd (open "/dev/urandom" "read"))
(define /dev/urandom:/dev/urandom
(lambda ()
(let (random-value nil buf nil)
(when fd
(read fd buf 4)
(set 'random-value (div (max 1 (first (unpack "lu" buf))) max-32bit-int)))
random-value)))
(context MAIN)
> (/dev/urandom)
0.4954840036797067
> (/dev/urandom)
0.93390936822023
#!/usr/bin/newlisp
# Anti-primes are highly composite numbers
# Print each number that is more composite than all the numbers before it.
(define start-time (date-value))
(define maxiter 5000000)
(define lastn 1)
(define (prime? n) (= 1 (length (factor n))))
(define (combinations n k (r '()))
(if (= (length r) k)
(list r)
(let (rlst '())
(dolist (x n)
(setq rlst (append rlst
(combinations ((+ 1 $idx) n) k (append r (list x))))))
rlst)))
(define (all-factors lst)
(let (r '())
(for (j 1 (length lst))
(extend r (combinations lst j)))))
(define antiprime
(lambda ()
(for (i 2 maxiter)
(let (f (length (unique (sort (all-factors (factor i))))))
(when (> f lastn)
(println i ": " f (if (prime? f) " (prime)" ""))
(setq lastn f))))))
(antiprime)
(println "Runtime: " (- (date-value) start-time) " seconds")
(exit)
Quote
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
23903 ted 20 0 1542988 1.456g 2624 R 100.0 18.9 130:51.61 antiprime.lspQuote
(exec "command") => string-list
(exec "command" "input to command") => ?
ERR: symbol expected : [text] blahblahblah
$ vi foo.txt
type this: i[/text]<ESC>2050Im<ESC>:wq
$ newlisp
(set 'foo (read-file "foo.txt"))
=> works correctly
(save "foo.lsp" 'foo)
=> it doesn't complain...
(load "foo.lsp")
ERR: symbol expected in function set : [/text]
Quote
(set 'foo '("#foo" "bar" "baz" "some text"))
Quote
(foo 0 0) => "#"
Quote
(cond
((= a b) foo)
(default bar))
Quote
(case a
(b foo)
(default bar))
Quote
> (set 'a "foorb" 'b "barnn")
> (regex "r|n$" a 256)
ERR: regular expression in function regex : "offset 0 unknown option bit(s) set"
Quote
int printw(const char *fmt, ...);
int wprintw(WINDOW *win, const char *fmt, ...);
int mvprintw(int y, int x, const char *fmt, ...);
int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...);
int vwprintw(WINDOW *win, const char *fmt, va_list varglist);
int vw_printw(WINDOW *win, const char *fmt, va_list varglist);
Quote
(import LIB_NCURSES "printw" "int" "void*")
(printw "abc %d %d %d" 1 2 3)
=> ERR: mismatch in number of arguments
(global 'foo)
(context 'bar)
(constant 'foo 2)
=> ERR: symbol not in current context in function constant : foo
Quote
Only symbols from the current context can be used with constant. This prevents the overwriting of symbols that have been protected in their home context.
char* foo(int index, int* retval);
(import MY_LIB "foo" "char*" "int" "void*")
(import MY_LIB "foo" "void*" "int" "void*")