Skip to content

Instantly share code, notes, and snippets.

@lokedhs
Created November 24, 2020 10:52
Show Gist options
  • Save lokedhs/bb552a05a6cb902a7fe730bf476d3ec1 to your computer and use it in GitHub Desktop.
Save lokedhs/bb552a05a6cb902a7fe730bf476d3ec1 to your computer and use it in GitHub Desktop.
(clim:define-command-table maxima-commands
:inherit-from (maxima-client.markup:text-commands
expression-commands
maxima-client.workbench:workbench-commands
watcher-commands
maxima-client.canvas:canvas-commands))
(clim:define-command (plot2d-with-range :name "Plot 2D" :menu t :command-table maxima-commands)
((expression maxima-native-expr :prompt "Expression")
(variable maxima-native-expr :prompt "Variable")
(lower-bound maxima-native-expr :prompt "Lower bound")
(upper-bound maxima-native-expr :prompt "Upper bound"))
(let ((plot2d-expression `((maxima::$plot2d) ,(maxima-native-expr/expr expression)
((maxima::mlist)
,(maxima-native-expr/expr variable)
,(maxima-native-expr-as-float lower-bound)
,(maxima-native-expr-as-float upper-bound)))))
(maxima-eval (make-instance 'maxima-native-expr :expr plot2d-expression))))
(clim:make-command-table 'maxima-menubar-command-table
:errorp nil
:menu '(("File" :menu maxima-file-command-table)
("Algebra" :menu maxima-algebra-command-table)
("Matrix" :menu maxima-matrix-command-table)
("Plot" :menu maxima-plot-command-table)
("Lisp" :menu maxima-lisp-command-table)
("Display" :menu maxima-interaction-command-table)
("Watcher" :menu maxima-watcher-command-table)
("Canvas" :menu maxima-client.canvas:maxima-canvas-command-table)
("Help" :menu maxima-help-command-table)))
(clim:make-command-table 'maxima-plot-command-table
:errorp nil
:menu '(("Discrete" :command `(plot2d-with-range
,clim:*unsupplied-argument-marker*
,clim:*unsupplied-argument-marker*
,clim:*unsupplied-argument-marker*
,clim:*unsupplied-argument-marker*))
("Parametric" :command plot2d-with-range)
("Plot example" :command plot2d-demo)))
@scymtym
Copy link

scymtym commented Nov 24, 2020

Reduced version with different cases of supplied and unsupplied arguments:

(clim:make-command-table 'menu-command-table
                         :errorp nil
                         :menu `(("Nothing" :command plot2d-with-range)
                                 ("Partial" :command (plot2d-with-range 1 2))
                                 ("Some unsupplied" :command (plot2d-with-range
                                                              ,clim:*unsupplied-argument-marker*))
                                 ("All unsupplied" :command (plot2d-with-range
                                                             ,clim:*unsupplied-argument-marker*
                                                             ,clim:*unsupplied-argument-marker*
                                                             ,clim:*unsupplied-argument-marker*
                                                             ,clim:*unsupplied-argument-marker*))
                                 ("All supplied" :command (plot2d-with-range 1 2 3 4))))

(clim:define-application-frame foo ()
  ()
  (:panes
   (label :label :label "foo")
   (int :interactor))
  (:layouts
   (:default
    (clim:vertically () label int)))
  (:command-table (foo :menu (("Foo" :menu menu-command-table)))))

(clim:define-command (plot2d-with-range :name "FourArgCommand" :command-table foo)
    ((expression 'integer :prompt "Expression")
     (variable 'integer)
     (lower-bound 'integer :prompt "Lower bound")
     (upper-bound 'integer)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment