diff --git a/init.jl b/init.jl index 552c436..5159244 100644 --- a/init.jl +++ b/init.jl @@ -231,12 +231,13 @@ const Mimes = Dict(:org => "text/org", function OrgBabelFormat(output_type::Symbol, output_file, - dir, vars, + dir, vars_file, src_file, silently::Bool, pure::Bool, kwargs) content = read(src_file, String) + vars = read(vars_file, String) # Fake a prompt with the current input try printstyled(IOContext(stdout, :color => true), diff --git a/ob-julia.el b/ob-julia.el index 4e1230c..9532001 100644 --- a/ob-julia.el +++ b/ob-julia.el @@ -224,20 +224,24 @@ values are Array taken from `VALUES', and assign it to `NAME'" ","))) (defun org-babel-julia-assign-to-named-tuple (name column-names values) - "Create a NamedTuple" - (format "%s = [%s]" name - (mapconcat - (lambda (i) - (concat - "(" (mapconcat - (lambda (j) - (format "%s=%S" - (nth j column-names) - (nth j (nth i values)))) - (number-sequence 0 (1- (length column-names))) - ",") - ")")) - (number-sequence 0 (1- (length values))) ", "))) + "Create a NamedTuple using (; zip([], [])...)" + (let ((res (format "%s = [%s]" name + (mapconcat + (lambda (i) + (concat + "(; zip([" + (mapconcat + (lambda (col) (format "Symbol(\"%s\")" col)) + column-names ", ") + "],[" + (mapconcat + (lambda (cell) (format "\"%s\"" cell)) + (nth i values) + ",") + "])...)")) + (number-sequence 0 (1- (length values))) ", ")))) + (message res) + res)) (defun org-babel-variable-assignments:julia (params) "Return list of julia statements assigning the block's variables." @@ -273,7 +277,8 @@ values are Array taken from `VALUES', and assign it to `NAME'" OUTFILE and FILE can either be a string or nil. If FILE is defined, output is _save()_d to a file with that name. else OUTFILE is used, and data is _write()_ to it." - (let* ((vars (org-babel-variable-assignments:julia params)) + (let* ((vars (mapconcat 'concat (org-babel-variable-assignments:julia params) ";")) + (varsfile (make-temp-file "ob-julia-vars-" nil ".jl" vars)) (dir (or (cdr (assoc :dir params)) default-directory)) (using-param (cdr (assoc :using params))) (using (if using-param (split-string using-param) nil)) @@ -298,7 +303,7 @@ else OUTFILE is used, and data is _write()_ to it." "OrgBabelFormat(%s,%S,%S,%S,%S,%s,%s,%S);" output-type outfile dir - (mapconcat 'concat vars ";") srcfile + varsfile srcfile (if org-babel-julia-silent-repl "true" "false") (if (ob-julia-check-trueness params :let)