From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yi Wang Subject: Re: Babel language support for Mathematica Date: Fri, 13 Mar 2015 23:16:36 +0000 Message-ID: References: <0E109199-8E68-4B76-A1D9-20105FF0C1D3@haas.berkeley.edu> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c2e5583567dc051133b105 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWYoq-0002Nw-7S for emacs-orgmode@gnu.org; Fri, 13 Mar 2015 19:16:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YWYoo-0007Tt-P1 for emacs-orgmode@gnu.org; Fri, 13 Mar 2015 19:16:40 -0400 Received: from mail-ob0-x233.google.com ([2607:f8b0:4003:c01::233]:35098) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWYoo-0007Tl-HN for emacs-orgmode@gnu.org; Fri, 13 Mar 2015 19:16:38 -0400 Received: by obfv9 with SMTP id v9so983531obf.2 for ; Fri, 13 Mar 2015 16:16:37 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: John Kitchin , Richard Stanton Cc: emacs-orgmode@gnu.org --001a11c2e5583567dc051133b105 Content-Type: text/plain; charset=UTF-8 Dear Richard, You can do: #+BEGIN_SRC mathematica f[x_] := x+3; f[5] #+END_SRC Here are explanations: I actually put everything in the SRC block into a Print[...]. So in the second example, what actually runs is Print[f[x_] := x+3 f[5]] This does not return any value. Because what it really does is print the value of "f[x_] := x+3 f[5]" Here is the code: (concat (mapconcat ;; define any variables (lambda (pair) (format "%s=%s;" (car pair) (org-babel-mathematica-var-to-mathematica (cdr pair)))) vars "\n") "\nPrint[\n" body "\n]\n") If anybody has idea to improve it, I will be happy to see and work it out! Best, Yi On Sat, Mar 14, 2015 at 7:09 AM John Kitchin wrote: > I wonder if this is an output vs value issue on the return of the > block. If you set :results output does anything change? or, is there a > way to specify a return value? or specifically print something? > > Richard Stanton writes: > > > I recently saw this posting about org support for Mathematica. Thanks > for writing this! > > > > Unfortunately, while I can get it to work for simple things (e.g., 2+3), > even slightly more complex things don't seem to work. For example, suppose > I'd like to define a function f(x) = x + 3, and then calculate f(5). In a > MMA notebook, if I type > > > > f[x_] := x+3 > > f[5] > > > > I get the answer 8. If I try the same code in an org-mode code block, > here's what happens: > > > > #+BEGIN_SRC mathematica > > f[x_] := x+3 > > f[5] > > #+END_SRC > > > > #+RESULTS: > > : Null > > > > Am I missing something obvious here? > > > > Thanks very much. > > > > Richard Stanton > > -- > Professor John Kitchin > Doherty Hall A207F > Department of Chemical Engineering > Carnegie Mellon University > Pittsburgh, PA 15213 > 412-268-7803 > @johnkitchin > http://kitchingroup.cheme.cmu.edu > --001a11c2e5583567dc051133b105 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Dear Richard,

You can do:

#+BEGIN_SRC mathe= matica
f[x_] :=3D x+3;
f[5]
#+END_SRC

Here = are explanations: I actually put everything in the SRC block into a Print[.= ..].

So in the second example, what actually runs is

=
Print[f[x_] :=3D x+3
f[5]]
<= br>
This does not return any value. Because what it really does i= s print the value of "f[x_] :=3D x+3=C2=A0f[5]"

Here is the code:

(concat
=C2=A0 =C2=A0 =C2=A0(mapconca= t ;; define any variables
=C2=A0 =C2=A0 =C2=A0 (lambda (pair)
(fo= rmat "%s=3D%s;"
(car pair)
(org-babel-mathematica-var-to-mathem= atica (cdr pair))))
=C2=A0 =C2=A0 =C2=A0 vars "\n") &qu= ot;\nPrint[\n" body "\n]\n")

= If anybody has idea to improve it, I will be happy to see and work it out!<= /div>

Best,
Yi



On Sat, Mar 14, 2015 at 7:09 AM= John Kitchin <jkitchin@andre= w.cmu.edu> wrote:
I wonder if this= is an output vs value issue on the return of the
block. If you set :results output does anything change? or, is there a
way to specify a return value? or specifically print something?

Richard Stanton writes:

> I recently saw this posting about org support for Mathematica. Thanks = for writing this!
>
> Unfortunately, while I can get it to work for simple things (e.g., 2+3= ), even slightly more complex things don't seem to work. For example, s= uppose I'd like to define a function f(x) =3D x + 3, and then calculate= f(5). In a MMA notebook, if I type
>
> f[x_] :=3D x+3
> f[5]
>
> I get the answer 8. If I try the same code in an org-mode code block, = here's what happens:
>
> #+BEGIN_SRC mathematica
> f[x_] :=3D x+3
> f[5]
> #+END_SRC
>
> #+RESULTS:
> : Null
>
> Am I missing something obvious here?
>
> Thanks very much.
>
> Richard Stanton

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitc= hingroup.cheme.cmu.edu
--001a11c2e5583567dc051133b105--