Edit
Attach
Printable
topic end
<!-- * Set TOPICTITLE = #define private public - So long, and thanks for all the functional fish! (30 Mar 2008) --> <style type="text/css"> pre {background-color:#ffeecc;} </style> %STARTINCLUDE% <a name="30"></a> ---+++ [[DefinePrivatePublic20080330FunctionalFish][So long, and thanks for all the functional fish!]] (30 Mar 2008) <a href="%ATTACHURL%/functional_cocreate_big.png"> <img src="%ATTACHURL%/functional_cocreate.png" border="0" style="float:right;" align="right" /></a> <summary>1982. I'm not even sure if I already had my first computer back then - but that's the year when Peter Henderson published an article about <a href="http://users.ecs.soton.ac.uk/ph/funcgeo.pdf">Functional Geometry</a>, in which he describes how to build images from equations, and how to create big images from smaller ones using functional composition. </summary> The original implementation was in UCSD Pascal. A while ago, part-time Lisp hacker Frank Buß ported it to Lisp and added Postscript output, and he also posted a [[http://www.frank-buss.de/lisp/functional.html][very nice description]] of his approach, illustrating how this example helped him understand how valuable support for higher-order functions in a language can be. Frank's code is clear and compact, and the platform dependencies are all in one function, which made it easy to adapt to <nop>CoCreate Modeling's dialect of Common Lisp. In fact, all that's needed to run the code is the following loader code: <br clear="all" /> <pre> <font color="#0000ff">;; -*-Lisp-*-</font> <font color="#0000ff">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</font> <font color="#0000ff">;; Description: Wrapper to run Frank Buss' functional geometry code</font> <font color="#0000ff">;; in CoCreate Modeling</font> <font color="#0000ff">;; Author: Claus Brod </font> <font color="#0000ff">;; Language: Lisp</font> <font color="#0000ff">;;</font> <font color="#0000ff">;; (C) Copyright 2008 Claus Brod, all rights reserved</font> <font color="#0000ff">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</font> <font color="#0000ff">;;</font> <font color="#6a5acd">(</font><font color="#804040"><b>in-package</b></font> :clausbrod.de<font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>use-package</b></font> :oli<font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>export</b></font> <font color="#6a5acd">'</font><font color="#6a5acd">(</font>plot-escher<font color="#6a5acd">)</font><font color="#6a5acd">)</font> <font color="#0000ff">;; Allow using lambda without quoting it via #' first</font> <font color="#0000ff">;; (No longer required in CoCreate Modeling 2008 and later.)</font> <font color="#6a5acd">(</font><font color="#804040"><b>defmacro</b></font> <font color="#804040"><b>lambda</b></font> <font color="#6a5acd">(</font>&rest body<font color="#6a5acd">)</font> <font color="#a020f0">`(</font><font color="#804040"><b>function</b></font> <font color="#6a5acd">(</font><font color="#804040"><b>lambda</b></font> ,@body<font color="#6a5acd">)</font><font color="#a020f0">)</font><font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>defparameter</b></font> <font color="#2e8b57"><b>*our-loadpath*</b></font> <font color="#804040"><b>*load-truename*</b></font><font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>load</b></font> <font color="#6a5acd">(</font><font color="#804040"><b>format</b></font> <font color="#804040"><b>nil</b></font> <font color="#ff00ff">"~A/functional.lsp"</font> <font color="#6a5acd">(</font><font color="#804040"><b>directory-namestring</b></font> <font color="#2e8b57"><b>*our-loadpath*</b></font><font color="#6a5acd">)))</font> <font color="#0000ff">;; Modeling-specific plotter function</font> <font color="#6a5acd">(</font><font color="#804040"><b>defun</b></font> plot-annotation <font color="#6a5acd">(</font>p<font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>let</b></font> <font color="#6a5acd">((</font>tempfile <font color="#6a5acd">(</font><font color="#804040"><b>format</b></font> <font color="#804040"><b>nil</b></font> <font color="#ff00ff">"~A/test.mac"</font> <font color="#6a5acd">(</font>oli:sd-inq-temp-dir<font color="#6a5acd">)))</font> <font color="#6a5acd">(</font>scale <font color="#ff00ff">500.0</font><font color="#6a5acd">))</font> <font color="#6a5acd">(</font>startup::activate-annotation<font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>with-open-file</b></font> <font color="#6a5acd">(</font>s tempfile <font color="#2e8b57"><b>:direction</b></font> <font color="#2e8b57"><b>:output</b></font> <font color="#2e8b57"><b>:if-exists</b></font> <font color="#2e8b57"><b>:supersede</b></font><font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>format</b></font> s <font color="#ff00ff">"line~%"</font><font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>dolist</b></font> <font color="#6a5acd">(</font>line <font color="#6a5acd">(</font><font color="#804040"><b>funcall</b></font> p <font color="#6a5acd">'</font><font color="#6a5acd">(</font>0 0<font color="#6a5acd">)</font> <font color="#6a5acd">'</font><font color="#6a5acd">(</font>1 0<font color="#6a5acd">)</font> <font color="#6a5acd">'</font><font color="#6a5acd">(</font>0 1<font color="#6a5acd">)</font><font color="#6a5acd">))</font> <font color="#6a5acd">(</font><font color="#804040"><b>destructuring-bind</b></font> <font color="#6a5acd">((</font>x0 y0<font color="#6a5acd">)</font> <font color="#6a5acd">(</font>x1 y1<font color="#6a5acd">))</font> line <font color="#6a5acd">(</font><font color="#804040"><b>format</b></font> s <font color="#ff00ff">" ~D,~D ~D,~D~%"</font> <font color="#6a5acd">(</font><font color="#804040"><b>*</b></font> scale <font color="#6a5acd">(</font><font color="#804040"><b>float</b></font> x0<font color="#6a5acd">))</font> <font color="#6a5acd">(</font><font color="#804040"><b>*</b></font> scale <font color="#6a5acd">(</font><font color="#804040"><b>float</b></font> y0<font color="#6a5acd">))</font> <font color="#6a5acd">(</font><font color="#804040"><b>*</b></font> scale <font color="#6a5acd">(</font><font color="#804040"><b>float</b></font> x1<font color="#6a5acd">))</font> <font color="#6a5acd">(</font><font color="#804040"><b>*</b></font> scale <font color="#6a5acd">(</font><font color="#804040"><b>float</b></font> y1<font color="#6a5acd">)))))</font> <font color="#6a5acd">(</font><font color="#804040"><b>format</b></font> s <font color="#ff00ff">"end"</font><font color="#6a5acd">))</font> <font color="#6a5acd">(</font>oli:sd-execute-annotator-command :cmd <font color="#6a5acd">(</font><font color="#804040"><b>format</b></font> <font color="#804040"><b>nil</b></font> <font color="#ff00ff">"input '~A'"</font> tempfile<font color="#6a5acd">))</font> <font color="#6a5acd">(</font>docu::docu_vp :fit_vp<font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>delete-file</b></font> tempfile<font color="#6a5acd">)))</font> <font color="#0000ff">;; Shortcut for the Escher fish drawing</font> <font color="#6a5acd">(</font><font color="#804040"><b>defun</b></font> plot-escher<font color="#6a5acd">()</font> <font color="#6a5acd">(</font>plot-annotation <font color="#2e8b57"><b>*fishes*</b></font><font color="#6a5acd">))</font> </pre> The loader code adds the definition for the [[http://www.lisp.org/HyperSpec/Body/mac_lambda.html][lambda macro]] which is missing so far in <nop>CoCreate Modeling, loads Frank's code, and then adds a plotter function which creates output in a 2D Annotation window. Usage instructions: * Download [[http://www.frank-buss.de/lisp/functional.lisp.txt][Frank's code]] from his site and save it as =functional.lsp=. * Download the [[%ATTACHURL%/functional_cocreate_loader.lsp][loader code]] and save it into the same directory. * Load the loader Lisp code into <nop>CoCreate Modeling 2007 or higher. * In the user input line, enter =(clausbrod.de:plot-escher)= Thanks to Frank for this cute demo code! --- %STOPINCLUDE% %COMMENT{type="below" nonotify="on"}% ---
to top
End of topic
Skip to action links
|
Back to top
Edit
|
Attach image or document
|
Printable version
|
Raw text
|
Refresh
|
More topic actions
Revisions: | r1.1
|
Total page history
|
Backlinks
You are here:
Blog
>
DefinePrivatePublic20080330FunctionalFish
r1.1 - 31 Mar 2008 - 18:03 -
ClausBrod
to top
Blog
This site
2017
:
12
-
11
-
10
2016
:
10
-
7
-
3
2015
:
11
-
10
-
9
-
4
-
1
2014
:
5
2013
:
9
-
8
-
7
-
6
-
5
2012
:
2
-
10
2011
:
1
-
8
-
9
-
10
-
12
2010
:
11
-
10
-
9
-
4
2009
:
11
-
9
-
8
-
7
-
6
-
5
-
4
-
3
2008
:
5
-
4
-
3
-
1
2007:
12
-
8
-
7
-
6
-
5
-
4
-
3
-
1
2006:
4
-
3
-
2
-
1
2005:
12
-
6
-
5
-
4
2004:
12
-
11
-
10
C++
CoCreate Modeling
COM & .NET
Java
Mac
Lisp
OpenSource
Scripting
Windows
Stuff
Changes
Index
Search
Maintenance
Impressum
Datenschutzerklärung
Home
Webs
Atari
Blog
Claus
CoCreateModeling
Klassentreffen
Main
Sandbox
Sommelier
TWiki
Xplm
Jump:
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback