yamlscript

Markus Agwin 2024-05-24T11:24:13.478589Z

I'd like to point out one feature of Matlab(TM): if its usual end of line semicolon ; is omitted, the result of the statement is displayed on the console.

Ingy döt Net 2024-05-24T16:16:35.817329Z

Can you show me an online example or URL of a documentation or explanation?

Ingy döt Net 2024-05-24T16:18:56.333289Z

I haven't tried it yet but somebody told me that there is a way to put #p in front of a clojure form for a similar effect

Markus Agwin 2024-05-24T17:26:06.577959Z

I am thinking of a YS language extension. Whenever in YS there is a colon : one could write repl: so that the expression is printed. And then one has a file-watch-mode which only watches those expressions with repl: in them...

Ingy döt Net 2024-05-24T17:55:39.195829Z

Can you expand on that thought with a small example?

Markus Agwin 2024-05-24T18:00:52.383049Z

I can write a blog post where I explain; but I am sure when you write this idea to REPL people they will agree that this covers 80% of a REPL experience. Plus: YS would be a language where people (for the first time?) could write about how they use their REPL daily. Because at the time being it is so hard to understand what REPL means, but with this it would be immediately clear.

Ingy döt Net 2024-05-24T18:01:54.750149Z

I'm just not certain what you mean syntactically with your idea

Markus Agwin 2024-05-24T18:02:10.793589Z

ah, ok, mom

Markus Agwin 2024-05-24T18:04:24.687599Z

Instead of

say:
  +: 1 2

one could write
+ repl: 1 2

and get the same output 3

Markus Agwin 2024-05-24T18:05:23.384159Z

but one could also write

say:
  + repl: 1 2
and get twice the number 3 on the console

Ingy döt Net 2024-05-24T18:06:16.731279Z

That's one way for sure. I can think of a couple others and also different contexts.

Ingy döt Net 2024-05-24T18:07:32.588259Z

I'll retort after I finish doing the dishes

👍 1
Markus Agwin 2024-05-24T18:07:48.356129Z

but in file-watch-mode, one would at initial run see twice the number 3 on the console but YS would not terminate but watch for changes in the file. And if the file is changed, only expressions with repl: in them would be evaluated. So for example if one changes the 1 to 4 and save the file, one would only see 6 once on screen.

Markus Agwin 2024-05-24T18:59:29.545189Z

The Matlab idea is described under the "Use of Semicolon (;) in MATLAB" header at URL https://www.tutorialspoint.com/matlab/matlab_syntax.htm

✅ 1
Ingy döt Net 2024-05-24T19:02:45.910059Z

Here's my quick ideas on this:

!yamlscript/v0

defn fn1(a b): 
  c =:
    +: a b 
  =>: c * 3 

defn fn2(a b): 
  c =:
    repl:
      +: a b 
  =>: c * 3 

defn fn3(a b):
  c =: !repl:
    +: a b
  =>: c * 3

defn fn4(a b): 
  c =: !repl:
    +: a b 
  =>: (c * 3).repl()

Ingy döt Net 2024-05-24T19:07:15.989939Z

• fn1 is an example fn • we want to avoid doing fn2 style as it requires indentation (but it would work fine) • I thought I already implemented "tag function calls" in YS but maybe it's on a branch? I can't find it. The idea is that YAML tags consisting of a symbol word and ending with a : compile to a function call using the node as an argument... • Chaining functions calls on yes expressions work anywhere. You'll want this to work with both mapping pair calls and yes-expr calls.

👍 1
Ingy döt Net 2024-05-24T19:08:32.257699Z

the !foo: is really powerful. I was sure I implemented it but maybe not... it's also usable to call functions in data mode without switching modes first

Ingy döt Net 2024-05-24T19:09:41.078439Z

the foo repl: bar doesn't work out quite as well hygenically

Ingy döt Net 2024-05-24T19:10:07.592459Z

I can explain more later on, but I have to go afk now

Ingy döt Net 2024-05-24T19:12:47.738229Z

I'll figure out what the status !foo: is. Perplexed on that

Ingy döt Net 2024-05-24T19:16:43.331509Z

I think the driving use case was merging maps in data mode:

blah: !
  merge:
    =>: *map1
    =>: !
      key1: val1
can be:
blah: !merge:
- *map1
- key1: val1

Ingy döt Net 2024-05-24T19:17:58.095159Z

We don't see tags in YAML usage much. In YS so far we see !yamlscript/v0 and ! so far

Ingy döt Net 2024-05-24T19:18:42.915359Z

I think tags can play a big part in YS, used judiciously

Ingy döt Net 2024-05-24T19:19:36.259509Z

one thing I've wanted for some time is !clj for specifying a pur clojure node...

Ingy döt Net 2024-05-24T19:20:27.816779Z

YS syntax is not yet set up to write Clojure macros (with macro syntax forms) very well yet

Ingy döt Net 2024-05-24T19:22:03.017569Z

ok out of time 🙂 thanks for the repl/debugging ideas. We'll make it slick

Markus Agwin 2024-05-24T19:25:31.512869Z

The !foo: case is exactly what I was looking for. But I did not get it to work. But certainly nowhere near urgent. It is just that the Matlab people love this semicolon trick. One guy stated this feature as a reason not to use Python. So I thought I bring it up. Thank you for the quick response.

Markus Agwin 2024-05-29T08:20:47.318129Z

The www function is a fine invention indeed! On the Matlab example, in addition to your observation that it prints value+context, I'd like to point out Matlab's Ctrl+E , which triggers execution of the file. In effect they have a Repl-feel with this (feel only, because it does read file from disk, run, stop -- no Repl-real with its omnipresent internal state). And I think this Repl-feel is part of Matlab success. Now I also think one hurdle to wider adoption of Repl-real is its need for nrepl connection of the Editor. Notepad++ users, hence scripting-people (not developers), do not have a chance to taste the Repl-feel. But we have in Clojure a tradition started by Bruce Hauman -- it is Figwheel hot reload. He realised that thinking in terms of "file on disk" has its appeal and the wide adoption of hot-reload I think proves him right. Thus, before implementing nrepl, a file watcher in YAMLScript would be, I think, a step to at least consider.

Ingy döt Net 2024-05-29T08:26:09.279109Z

All of that is going to take me some time to digest. Might need to discuss it point by point with you...

Markus Agwin 2024-05-29T08:27:08.688889Z

Hammock time, discuss with other people as well, is very necessary

✅ 1
Ingy döt Net 2024-05-29T08:27:29.008289Z

www is from https://metacpan.org/pod/XXX which I always port to any language I use 🙂

Ingy döt Net 2024-05-29T08:28:47.060949Z

It's one of my constant debugging tools for writing the code for ys

Ingy döt Net 2024-05-29T08:29:34.429089Z

right now I'm using it to debug my ys and clj versions of https://rosettacode.org/wiki/Weird_numbers 😄

Ingy döt Net 2024-05-29T08:30:42.641069Z

The coding of which has led me to at least 3 things I want to make ys better

Markus Agwin 2024-05-29T08:39:21.041049Z

This XXX-YYY-ZZZ driven development should become the idiomatic way for every YS disciple. I just saw it for the first time, but it rings a bell. Do you use nrepl-connection for the Word_numbers implementation, or do you use the brisk startup time and run-file-from-disk?

Ingy döt Net 2024-05-29T08:42:13.618299Z

both

Ingy döt Net 2024-05-29T08:42:35.366459Z

mostly nrepl

Ingy döt Net 2024-05-28T09:36:57.050939Z

I just realized the matlab semicolon thing is more than I thought

Ingy döt Net 2024-05-28T09:37:51.239759Z

for their example

x = 3;
y = x + 5
it prints:
y = 8

Ingy döt Net 2024-05-28T09:38:13.761569Z

not just 8... That's pretty cool

Ingy döt Net 2024-05-28T09:42:30.202409Z

I was just thinking of having a function that printed the node value, or sent it to the repl

Ingy döt Net 2024-05-28T09:42:59.207729Z

but if it could also show the context of where that value came from

Ingy döt Net 2024-05-28T09:44:20.592359Z

btw there is a std www function that prints a value to stderr then returns the value:

$ cat foo.ys 
!yamlscript/v0/

a:
  b:
  - c
  - !
    www: 2 ** 10
  - d
$ ys -Y foo.ys 
---
1024.0
...
a:
  b:
  - c
  - 1024.0
  - d
(it wraps output with --- and ... lines)