From tito.01beta at gmail.com Sun Aug 1 01:47:37 2021 From: tito.01beta at gmail.com (Tito Latini) Date: Sun, 1 Aug 2021 10:47:37 +0200 Subject: [CM] Sending code to the REPL from Emacs In-Reply-To: References: Message-ID: <20210801084737.GA1731@vis.roboris> On Sat, Jul 31, 2021 at 10:52:19PM +0000, Brad Christensen wrote: > Any Emacs users out there with working s7 REPL configs? > > I quite like the idea of keeping certain code in an org file and sending code to the REPL. > [...] I can share my Babel functions for Snd-Scheme Evaluation. They are based on ob-lisp.el (GPL). This message includes two attached files: - ob-snd-scheme.el - snd-scheme-example.org Copy ob-snd-scheme.el to a directory in your load-path and update the alist (org-babel-do-load-languages 'org-babel-load-languages ((snd-scheme . t) [...])) in .emacs file (or require ob-snd-scheme) to enable the language. See also [[info:org#Languages]] Note: if the output is a sequence, it is corrupted if the length is less than print-length. -------------- next part -------------- ;;; Babel Functions for Snd-Scheme Evaluation based on ob-lisp.el ;;; (GNU General Public License ). ;;; Tito Latini 2018 ;;; Note: if the output is a sequence, it is corrupted if the length ;;; is less than print-length. (defun org-babel-expand-body:snd-scheme (body params) "Expand BODY according to PARAMS, return the expanded body." (let* ((vars (org-babel--get-vars params)) (body (format "(let (%s)\n%s)" (mapconcat (lambda (var) (format "(%S (quote %S))" (car var) (cdr var))) vars "\n ") body))) (if (intersection '("code" "pp") (cdr (assq :result-params params)) :test #'string=) (format "(snd-print %s)" body) body))) (defun org-babel-execute:snd-scheme (body params) "Execute a block of Snd-Scheme code with Babel. BODY is the contents of the block, as a string. PARAMS is a property list containing the parameters of the block." (org-babel-reassemble-table (let ((result (with-temp-buffer (insert (org-babel-expand-body:snd-scheme body params)) (let* ((str "") (comint-output-filter-functions (list (lambda (text) (setq str (concat str text))))) (proc (get-buffer-process (inf-snd-proc-buffer)))) (comint-send-region proc (point-min) (point-max)) (comint-send-string proc "\n") (accept-process-output proc) (subseq str 0 (position ?\n str :from-end t)))))) (org-babel-result-cond (cdr (assq :result-params params)) result (condition-case nil (read (org-babel-snd-scheme-vector-to-list result)) (error result)))) (org-babel-pick-name (cdr (assq :colname-names params)) (cdr (assq :colnames params))) (org-babel-pick-name (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))) (defun org-babel-snd-scheme-vector-to-list (results) (replace-regexp-in-string "#\\(i\\|r\\)?(" "(" results)) (provide 'ob-snd-scheme) -------------- next part -------------- #+name: tab | 10 | | 20 | | 30 | | 40 | | 50 | Start the inferior Snd-Scheme process if necessary: [[elisp:run-snd-scheme]] #+name: zoo #+begin_src snd-scheme :var input=tab n=7 (map (lambda (x) (list (* n (car x)))) input) #+end_src #+RESULTS: zoo | 70 | | 140 | | 210 | | 280 | | 350 | #+name: seq-1 #+begin_src shell :var n=10 seq $n #+end_src #+call: zoo(seq-1,3) #+RESULTS: | 3 | | 6 | | 9 | | 12 | | 15 | | 18 | | 21 | | 24 | | 27 | | 30 | The output is not correct if list length is 40 but ~print-length~ is 32: #+call: zoo(seq-1(40)) #+RESULTS: | (7) | (14) | (21) | (28) | (35) | (42) | (49) | (56) | (63) | (70) | (77) | (84) | (91) | (98) | (105) | (112) | (119) | (126) | (133) | (140) | (147) | (154) | (161) | (168) | (175) | (182) | (189) | (196) | (203) | (210) | (217) | (224) | ... | A possible fix is ~(set! (print-length) 100)~ in Snd. #+begin_src snd-scheme (set! (print-length) 100) (new-sound "new.snd" :size 96 :srate 48000) (clm-channel (make-oscil 880)) (map list (channel->float-vector)) #+end_src #+RESULTS: | 0.0 | | 0.1149371504928666 | | 0.22835087011065572 | | 0.33873792024529137 | | 0.44463517918492745 | | 0.544639035015027 | | 0.6374239897486896 | | 0.721760228098362 | | 0.7965299180241961 | | 0.8607420270039434 | | 0.9135454576426008 | | 0.9542403285162767 | | 0.9822872507286886 | | 0.9973144772244581 | | 0.9991228300988584 | | 0.9876883405951379 | | 0.9631625667976583 | | 0.9258705848099951 | | 0.8763066800438639 | | 0.8151277957285546 | | 0.7431448254773948 | | 0.6613118653236525 | | 0.5707135676844325 | | 0.4725507648690549 | | 0.368124552684679 | | 0.25881904510252185 | | 0.14608302856241281 | | 0.03141075907812957 | | -0.08367784333231415 | | -0.19765734037912477 | | -0.309016994374946 | | -0.41628079226039977 | | -0.5180270093731288 | | -0.6129070536529752 | | -0.6996633405133642 | | -0.77714596145697 | | -0.8443279255020143 | | -0.9003187714021929 | | -0.9443763702374806 | | -0.9759167619387471 | | -0.9945218953682732 | | -0.9999451693655121 | | -0.9921147013144781 | | -0.9711342799096365 | | -0.9372819894918921 | | -0.8910065241883688 | | -0.8329212407101007 | | -0.7637960286346436 | | -0.6845471059286903 | | -0.5962248749656176 | | -0.500000000000002 | | -0.3971478906347828 | | -0.2890317969444739 | | -0.17708474031958574 | | -0.06279051952931593 | | 0.05233595624294122 | | 0.16676874671609962 | | 0.2789911060392266 | | 0.3875155864521004 | | 0.4909037536151383 | | 0.5877852522924708 | | 0.6768759696826585 | | 0.7569950556517544 | | 0.82708057427456 | | 0.8862035792312132 | | 0.9335804264972006 | | 0.9685831611286303 | | 0.9907478404714432 | | 0.9997806834748454 | | 0.9955619646030803 | | 0.9781476007338062 | | 0.9477684100095866 | | 0.9048270524660207 | | 0.8498926929868654 | | 0.7836934573258416 | | 0.7071067811865497 | | 0.6211477802783127 | | 0.5269557954966803 | | 0.42577929156507555 | | 0.31895930929807303 | | 0.2079116908177626 | | 0.09410831331851768 | | -0.020942419883353512 | | -0.1357155724343009 | | -0.24868988716485133 | | -0.3583679495452969 | | -0.46329603511985845 | | -0.5620833778521275 | | -0.6534206039901025 | | -0.7360970871197317 | | -0.8090169943749451 | | -0.8712138111201875 | | -0.921863151588499 | | -0.960293685676942 | | -0.9859960370705042 | | -0.9986295347545736 | From bil at ccrma.Stanford.EDU Mon Aug 2 13:20:52 2021 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Mon, 02 Aug 2021 13:20:52 -0700 Subject: [CM] Snd 21.6 Message-ID: Snd 21.6: s7.h: added s7_is_random_state, s7_make_normal_vector, s7_array_to_list s7.c: I changed the default heap size to 64k (half its previous size) -- my timing tests and benchmarks seem to indicate that this is usually faster (perhaps cache-related?). Pushing it down to 32k doesn't affect runtimes very much. To get the old size back, (set! (*s7* 'heap-size) 128000). Checked: sbcl 2.1.7 Thanks!: Daniel Hensel, Brad Christensen, James Hearon, Christos Vagias, Tito Latini, Elijah Stone, Kjetil Matheussen, Woody Douglass (Sourceforge had an "internal error", so the new tarball isn't available there currently -- I'll try again tomorrow). From bchristensen-lists at outlook.com Sat Aug 21 11:05:26 2021 From: bchristensen-lists at outlook.com (Brad Christensen) Date: Sat, 21 Aug 2021 18:05:26 +0000 Subject: [CM] cload rebuilds don't consider *load-path* Message-ID: Greetings, Consider the following project tree, with the current working directory being 'some-project': some-project |-- source/scheme/some-lib | |-- example.scm --> (which uses cload to build a library) | . . . When *load-path* contains "source/scheme", the following load works as expected: > (load "some-lib/example.scm") However, it will not rewrite and rebuild the corresponding .c file, even when example.scm is newer than the previously generated .so library. For that, the path given to load needs to be the entire path from the cwd: > (load "source/scheme/some-lib/example.scm") I believe this is because the load-path is not considered when setting `port-filename`. Even though the file to load was found via a path in *load-path*, it believes itself not to exist when testing for a rebuild of the library. See line 741 in cload.scm, the conditional test for writing and building the .c file: ```scheme 736 (unless (and output-name 737 (file-exists? c-file-name) 738 (file-exists? so-file-name) 739 (provided? 'system-extras) 740 (>= (file-mtime so-file-name) (file-mtime c-file-name)) 741 (not (and (file-exists? (port-filename)) 742 (< (file-mtime so-file-name) (file-mtime (port-filename)))))) ``` Indeed, "some-project/some-lib/example.scm" does not exist. Can `port-filename` be made to expand to include whatever load-path the file was found to reside in? Cheers, Brad From bil at ccrma.Stanford.EDU Sat Aug 21 13:07:29 2021 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Sat, 21 Aug 2021 13:07:29 -0700 Subject: [CM] cload rebuilds don't consider *load-path* In-Reply-To: References: Message-ID: Thanks for the bug report. I think port-filename can include the load-path, but I'll need to look at the code more. Then realpath could give the full filename, if it is needed. I can't remember if you can get the full filename from the FILE* pointer (this would be the best option because the port struct contains that pointer). From bil at ccrma.Stanford.EDU Sun Aug 22 08:22:58 2021 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Sun, 22 Aug 2021 08:22:58 -0700 Subject: [CM] cload rebuilds don't consider *load-path* In-Reply-To: References: Message-ID: <5c8a05e8a9f03e97af58a685deaf1151@ccrma.stanford.edu> I changed the load process to keep more of the filename -- haven't had time to test it much. Pleas let me know of any problems. From bchristensen-lists at outlook.com Sun Aug 22 09:23:56 2021 From: bchristensen-lists at outlook.com (Brad Christensen) Date: Sun, 22 Aug 2021 16:23:56 +0000 Subject: [CM] cload rebuilds don't consider *load-path* In-Reply-To: <5c8a05e8a9f03e97af58a685deaf1151@ccrma.stanford.edu> References: <5c8a05e8a9f03e97af58a685deaf1151@ccrma.stanford.edu> Message-ID: > I changed the load process to keep more of the filename -- > haven't had time to test it much.? Pleas let me know > of any problems. I gave it a run and it looks to have solved my issue. Thank you! From iainduncanlists at gmail.com Tue Aug 24 06:35:02 2021 From: iainduncanlists at gmail.com (Iain Duncan) Date: Tue, 24 Aug 2021 06:35:02 -0700 Subject: [CM] Scheme for Max paper at ICFP 2021 Scheme Track Message-ID: Hi everyone, I just wanted to let everyone know that s7 will be featured in at ICFP through my paper "Scheduling Musical Events in Max/MSP with Scheme For Max". I'll be doing a presentation Saturday, but it will mostly be aimed at non-computer-music people who have no idea what Max or s7 is. The paper however, might be of interest to people, and the preprint version is up now here: (I think at least a few people on here are cited.) https://icfp21.sigplan.org/details/scheme-2021-papers/12/Scheduling-Musical-Events-in-Max-MSP-with-Scheme-For-Max -------------- next part -------------- An HTML attachment was scrubbed... URL: From wdouglass at carnegierobotics.com Tue Aug 24 10:49:22 2021 From: wdouglass at carnegierobotics.com (Woody Douglass) Date: Tue, 24 Aug 2021 17:49:22 +0000 Subject: [CM] length of output_string Message-ID: All, Does it make sense to have s7_get_output_string also return the length of the string? i'm working on a program that does some binary IO, and there are some 0s in my stream... so the new signature would be const char *s7_get_output_string(s7_scheme *sc, s7_pointer out_port, size_t *len); if the signature needs to remain compatible, i could make that last argument variadic, and then just document the behavior... Thanks, Woody Douglass From bil at ccrma.Stanford.EDU Tue Aug 24 11:06:51 2021 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Tue, 24 Aug 2021 11:06:51 -0700 Subject: [CM] =?utf-8?q?length_of_output=5Fstring?= In-Reply-To: References: Message-ID: <1dadb8059c1cb07f598b4ee69f87545a@ccrma.stanford.edu> In scheme there's a port-position function that would return the length; it could be exported as s7_port_position. Or a new function, say s7_output_string could return an s7_string (which can contain nulls), rather than a C string, and s7_string_length would give its length. Do these sound usable? From iainduncanlists at gmail.com Tue Aug 31 11:45:47 2021 From: iainduncanlists at gmail.com (Iain Duncan) Date: Tue, 31 Aug 2021 11:45:47 -0700 Subject: [CM] creating text code from s7 objects? Message-ID: Hi list, I just thought I'd check here before I do any silly wheel reinventing. Is there a decent way to go from s7 objects to strings of the objects exactly as would need to put them in a text editor? I imagine I'll have to do some massaging, but for example I want to make something that could receive a hash-table as an argument and output (hash-table :a 1 .....) thanks! iain -------------- next part -------------- An HTML attachment was scrubbed... URL: From elronnd at elronnd.net Tue Aug 31 12:23:34 2021 From: elronnd at elronnd.net (Elijah Stone) Date: Tue, 31 Aug 2021 12:23:34 -0700 (PDT) Subject: [CM] creating text code from s7 objects? In-Reply-To: References: Message-ID: On Tue, 31 Aug 2021, Iain Duncan wrote: > Is there a decent way to go from s7 objects to strings of the objects > exactly as would need to put them in a text editor? (object->string ... :readable) This can even serialise closures. But obviously you lose reference semantics. From bil at ccrma.Stanford.EDU Tue Aug 31 12:40:11 2021 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Tue, 31 Aug 2021 12:40:11 -0700 Subject: [CM] =?utf-8?q?creating_text_code_from_s7_objects=3F?= In-Reply-To: References: Message-ID: > (object->string ... :readable) also format with ~W (which calls the same code). There are a few things that resist serialization: continuations for example. From bil at ccrma.Stanford.EDU Tue Aug 31 12:46:39 2021 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Tue, 31 Aug 2021 12:46:39 -0700 Subject: [CM] =?utf-8?q?creating_text_code_from_s7_objects=3F?= In-Reply-To: References: Message-ID: <1874afa9efe04d6de2cc4310d8825a19@ccrma.stanford.edu> but now that I think about it (with an ever-widening smile), s7 could include some reasonable facsimile of the continuation stack and let chain. To be callable, it might also need the rootlet entries that it references. From iainduncanlists at gmail.com Tue Aug 31 12:53:34 2021 From: iainduncanlists at gmail.com (Iain Duncan) Date: Tue, 31 Aug 2021 12:53:34 -0700 Subject: [CM] creating text code from s7 objects? In-Reply-To: <1874afa9efe04d6de2cc4310d8825a19@ccrma.stanford.edu> References: <1874afa9efe04d6de2cc4310d8825a19@ccrma.stanford.edu> Message-ID: Ah fantastic, thanks fellows! glad I asked, again! iain On Tue, Aug 31, 2021 at 12:47 PM wrote: > but now that I think about it (with an ever-widening smile), > s7 could include some reasonable facsimile of the continuation > stack and let chain. To be callable, it might also need the > rootlet entries that it references. > > _______________________________________________ > Cmdist mailing list > Cmdist at ccrma.stanford.edu > https://cm-mail.stanford.edu/mailman/listinfo/cmdist > -------------- next part -------------- An HTML attachment was scrubbed... URL: From iainduncanlists at gmail.com Tue Aug 31 15:02:55 2021 From: iainduncanlists at gmail.com (Iain Duncan) Date: Tue, 31 Aug 2021 15:02:55 -0700 Subject: [CM] possibly a file output bug Message-ID: Hi Bill, I am having this unusual behaviour and am wondering if it's a bug This works fine: (call-with-output-file "/Users/iainduncan/froms4m.txt" (lambda (output-port) (display "hello world, from s4m" output-port))) But if I put a hyphen in the file name ("/Users/iainduncan/from-s4m.txt"), I get the following error: ;open-output-file: Is a directory "/Users/iainduncan/from-s4m.txt" ; (call-with-output-file "/Users/iainduncan... FWIW, underscores are fine too. thanks! iain -------------- next part -------------- An HTML attachment was scrubbed... URL: From iainduncanlists at gmail.com Tue Aug 31 15:44:58 2021 From: iainduncanlists at gmail.com (Iain Duncan) Date: Tue, 31 Aug 2021 15:44:58 -0700 Subject: [CM] reading text from file to eval (as in... the other way!) Message-ID: Hi Bill and Elijah, that's working like a charm, this is going to be wonderful for being able combine file i/o with live coding. How would you recommend going the other way? I want to read the entire file in, and then just eval it to replace the serializable data arg. (my sequencer objects keep serializable "save" data separate from other internal data in a hash, so that part should be simple) I'm seeing read-string is defined in s7, but then I guess I need to know the max file size eh? Is there any downside to just setting it very big? thanks! iain -------------- next part -------------- An HTML attachment was scrubbed... URL: From bil at ccrma.Stanford.EDU Tue Aug 31 15:54:12 2021 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Tue, 31 Aug 2021 15:54:12 -0700 Subject: [CM] possibly a file output bug In-Reply-To: References: Message-ID: <8ba7754e3059312ea19210b9e3cce937@ccrma.stanford.edu> Are you sure that /Users/iainduncan/from-s4m.txt is not a directory? s7 just calls fopen with the desired name (and mode), and if that call fails, uses strerror to report what happened -- about as simple as IO can get. I tried both Linux and OSX cases, and had no problems with hyphens. From bil at ccrma.Stanford.EDU Tue Aug 31 16:02:15 2021 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Tue, 31 Aug 2021 16:02:15 -0700 Subject: [CM] reading text from file to eval (as in... the other way!) In-Reply-To: References: Message-ID: > I need to know the max file size You mean max-string-length, I think -- it defaults to 2^30. There is no downside to making it as big as you want. Loading is not noticeably more expensive than evalling -- I would just load the file again to pick up the new data. Maybe I misunderstand the context. From iainduncanlists at gmail.com Tue Aug 31 16:02:23 2021 From: iainduncanlists at gmail.com (Iain Duncan) Date: Tue, 31 Aug 2021 16:02:23 -0700 Subject: [CM] possibly a file output bug In-Reply-To: <8ba7754e3059312ea19210b9e3cce937@ccrma.stanford.edu> References: <8ba7754e3059312ea19210b9e3cce937@ccrma.stanford.edu> Message-ID: Well that's embarrassing, you're right, it IS a directory, but I have no clue how it got there. I guess somehow I created a directory from Scheme when trying this stuff out. Which is weird, because all I was doing was calling port functions. So sorry!! iain On Tue, Aug 31, 2021 at 3:54 PM wrote: > Are you sure that /Users/iainduncan/from-s4m.txt is not > a directory? s7 just calls fopen with the desired name > (and mode), and if that call fails, uses strerror to > report what happened -- about as simple as IO can get. > I tried both Linux and OSX cases, and had no problems > with hyphens. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From iainduncanlists at gmail.com Tue Aug 31 16:06:15 2021 From: iainduncanlists at gmail.com (Iain Duncan) Date: Tue, 31 Aug 2021 16:06:15 -0700 Subject: [CM] reading text from file to eval (as in... the other way!) In-Reply-To: References: Message-ID: oh wow, I had not made the connection that it was that easy and I could just do: (set! _ (load "file")) Scheme (and s7) just keeps making me happier! thanks Bill! On Tue, Aug 31, 2021 at 4:02 PM wrote: > > I need to know the max file size > > You mean max-string-length, I think -- it defaults to 2^30. There is no > downside to making it as big as you want. > > Loading is not noticeably more expensive than evalling -- I would just > load the file again to pick up the new data. Maybe I misunderstand > the context. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: