Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Functional Geometry for fishes
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rainer Joswig  
View profile  
 More options Jan 29 2005, 11:42 pm
Newsgroups: comp.lang.lisp
From: Rainer Joswig <jos...@lisp.de>
Date: Sun, 30 Jan 2005 05:42:17 +0100
Local: Sat, Jan 29 2005 11:42 pm
Subject: Re: Functional Geometry for fishes
In article <ct0po8$57...@newsreader2.netcologne.de>,
 Frank Buss <f...@frank-buss.de> wrote:

> I never really understood how to use higher order functions as combinators,
> until I read the article from Peter Henderson about Functional Geometry.
> Now it is easy for me to use it in Lisp:

> http://www.frank-buss.de/lisp/functional.html
> http://www.frank-buss.de/lisp/fishes.pdf

A picture of playing around with the code in LispWorks CLIM
on my iMac G5:

http://lispm.dyndns.org/lisp/pics/fg.jpg

Note that you can have commands to manipulate pictures
(via command line, menus or even drag&drop) and
that CLIM can generate postscript.

The code looks like this:

(define-presentation-type picture ())

(define-presentation-method presentation-typep (object (type picture))
  (typep object 'function))

;;; Plotting

(defun clim-plot (p  &optional (stream *standard-output*))
  (fresh-line stream)
  (with-output-as-presentation (stream p 'picture :single-box t)
    (with-room-for-graphics (stream)
      (with-scaling (stream 200 200)
        (with-translation (stream 0.1 0.1)
          (loop for (x0 y0 x1 y1) in '((0 0 1 0) (1 0 1 1) (1 1 0 1) (0 1 0 0))
                do (draw-line* stream x0 y0 x1 y1))
          (dolist (line (funcall p (make-point 0 0) (make-point 1 0) (make-point 0 1)))
            (destructuring-bind (p0 p1) line
              (draw-line stream p0 p1))))))))

(defun clim-plot-in-window (p &optional (stream *standard-output*))
  (clim-plot p stream))

(defun clim-plot-to-postscript (p &optional (pathname "/Users/joswig/Desktop/test-clim.ps"))
  (with-open-file (file-stream pathname
                               :direction :output
                               :if-exists :supersede
                               :if-does-not-exist :create)
   (with-output-to-postscript-stream (stream file-stream)
     (clim-plot p stream))))

(clim-demo::define-lisp-listener-command (clim-demo::save-picture-as-postscript :name t)
    ((picture 'picture :provide-default nil :prompt "picture")
     (file 'pathname :provide-default nil :prompt "file"))
  (clim-plot-to-postscript picture file)
  (values file picture))

(clim-demo::define-lisp-listener-command (clim-demo::com-beside :name t)
    ((picture0 'picture :provide-default nil :prompt "picture 0")
     (picture1 'picture :provide-default nil :prompt "picture 1"))
  (let ((new-picture (beside picture0 picture1)))
    (clim-plot new-picture)
    new-picture))

(clim-demo::define-lisp-listener-command (clim-demo::com-above :name t)
    ((picture0 'picture :provide-default nil :prompt "picture 0")
     (picture1 'picture :provide-default nil :prompt "picture 1"))
  (let ((new-picture (above picture0 picture1)))
    (clim-plot new-picture)
    new-picture))

(clim-demo::define-lisp-listener-command (clim-demo::com-rot :name t)
    ((picture 'picture :provide-default nil :prompt "picture"))
  (let ((new-picture (rot picture)))
    (clim-plot new-picture)
    new-picture))

(clim-demo::define-lisp-listener-command (clim-demo::com-cycle :name t)
    ((picture 'picture :provide-default nil :prompt "picture"))
  (let ((new-picture (cycle picture)))
    (clim-plot new-picture)
    new-picture))

(clim-demo::define-lisp-listener-command (clim-demo::com-quartet :name t)
    ((picture0 'picture :provide-default nil :prompt "picture 0")
     (picture1 'picture :provide-default nil :prompt "picture 1")
     (picture2 'picture :provide-default nil :prompt "picture 2")
     (picture3 'picture :provide-default nil :prompt "picture 3"))
  (let ((new-picture (quartet picture0 picture1 picture2 picture3)))
    (clim-plot new-picture)
    new-picture))

(define-presentation-to-command-translator rot
    (picture clim-demo::com-rot clim-demo::lisp-listener :menu t :gesture :menu)
    (object)
  (list object))

(define-presentation-to-command-translator cycle
    (picture clim-demo::com-cycle clim-demo::lisp-listener :menu t :gesture :menu)
    (object)
  (list object))

(define-drag-and-drop-translator besides
    (picture command picture clim-demo::lisp-listener
             :tester ((object destination-object)
                      (not (eq object destination-object))))
    (object destination-object)
  `(clim-demo::com-beside ,object ,destination-object))


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google