Metadata and Liveness

203 views
Skip to first unread message

Gilad Bracha

unread,
Jun 6, 2021, 5:53:13 PM6/6/21
to Newspeak Programming Language
Hello All,

I've just updated the public versions of the system and the spec. The spec now includes a finalized specification for metadata, which is implemented in the latest version.

As I've mentioned before, one of my goals is to make the Newspeak IDE more  live, so that one will be able to see exemplar values for every variable in the program (and therefore evaluate code everywhere, hence no dead code, no simulated execution in your head etc.). All in the sprit of:


Metadata is key to this vision. I wish I had realized that back in 2012/13. At the time I tried to address the problem the hard way, by figuring out exemplars automatically. I've since decided to use metadata from the user to guide the system.

Metadata are just comments that follow a convention, where the commented text begins with a colon-delimited tag, such as :exemplar: or :type: etc. The tag is followed by a payload, which I the metadata text itself.  The spec explains how metadata comments are associated with parts of the program. Mirrors provide access to metadata. Interpreting the metadata is entirely up to tools.

In particular, the IDE  now looks for metadata with the tag exemplar  factory methods. The payload of such metadata should be a valid invocation of the annotated method. For example,  given

class Foo: usingPlatform: p (* :exemplar: Foo usingPlatform: platform *) = ...

tells the IDE that one can create an exemplar instance of class Foo using the message

Foo usingPlatform: platform

The IDE will then choose to display the class via an object presenter on the exemplar. The object has its slots initialized so one can see their values and evaluate against self.
The class code is embedded in the object inspector.

If no exemplar tag is given (or if its evaluation fails) the system defaults to the regular class presenter.

The next step is to extend this to all methods, not just factories,.

Currently, there's only one annotated class, DeploymentManager, just to give a sense of how this will work. It also has one nested class annotated.  Going forward, I expect some timing of the object presenter will be needed to make this work well.  For example, we want the embedded class presenter open by default in these cases, we should display slot values near their declarations etc., support evaluation aside method editors etc.

Along the way, all code should be annotated in this way. The system should also be made to figure out simple cases (like classes whose factory is new, or any other unary method).

I expect to write a more careful exposition in a blog post in the next few weeks, when. this work is further along.

Gilad Bracha

unread,
Jul 5, 2021, 7:59:14 PM7/5/21
to newspeak...@googlegroups.com
It's been a month or so since my last update, so a new missive wouldn't be amiss. I've just updated the samples and apps tpo the latest version. This moves us a bit closer to the goal of a totally live system.
Now, if you annotate a method with exemplar metadata, and the surrounding class has an exemplar then the method will have a Debug button that will launch you into the debugger, at the start of the method, with arguments specified via the metadata. Unary methods don't need metadata. You can provide several exemplar annotations for the method, in which case pressing Debug will open a menu which lets you choose what exemplar metadata to use. The screenshot below illustrates what this looks like.

Again, very few classes and methods are annotated and I'm sure there are bugs lurking. Performance remains a serious problem. I'll comment on that later.

For a major class that has some exemplar annotations, you can look at MirrorsForPrimordialSoup. However, in many cases, this works without metadata annotation. If you open the nested class presenter in an object presenter, the object being viewed will be used as an exemplar, and any unary methods will have the Debug button automatically.
Likewise, top level classes with unary factories open in object inspectors without need for metadata, and nested classes with unary factories will do so if their enclosing class has an exemplar.

Workspaces, being essentially inspectors on instances of class Workspace, will also showcase this functionality.

The next step is to leverage this information more thoroughly in the UI.  For example, we should be able to support evaluation of arbitrary expressions inside method editors, or even allow you to type in code with live evaluation on, so you see what the results are as you type. Obviously, turning exemplars into tests and vice versa should be supported as well. A small matter of programming.

My goal is to have that sort of stuff implemented by early August, which means in 3 or 4 weekends of work.



Screen Shot 2021-07-05 at 16.26.05.png


--
You received this message because you are subscribed to the Google Groups "Newspeak Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to newspeaklangua...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/newspeaklanguage/bf6ec262-db5c-4eb2-876e-d99d0734df87n%40googlegroups.com.


--
Cheers, Gilad

Gilad Bracha

unread,
Aug 6, 2021, 4:42:59 PM8/6/21
to Newspeak Programming Language
Here's a short video on the use of exemplars in the IDE. This stuff is still incomplete and very buggy, but it's in master, and in the latest downloads and on the sample web page.

Milan Zimmermann

unread,
Aug 7, 2021, 8:44:18 PM8/7/21
to Newspeak Programming Language
Gilad, 

I just watched the videos and finally read this thread. This is really cool. 

I should really start using it and ask questions later, but this seems quite clear and easy :) 

Let me do a few comments and questions anyway


- Are the exemplars always extracted from the comment before the " = (..)" section defining the factory constructor, instance method or class method, or can the :exemplar: section be in any comment inside the method, factory or class method?

- If one has a class and wants to add an :exemplar: to it properly, one has to be dilligent and add them *on every method that provides instance "inputs"* - constructors, instance and class methods - otherwise evaluations in places that relies on some un-exemplared section would be confusing or incorrect (using nil or something like that?), is that a reasonable assumption? Also, I assume that super factories and methods need to be exemplared for it to fully function.  Or is there perhaps some tool that checks missing exemplar inputs througout the class definition?

- Answer to this is probably obvious, but here:  In the video, the debug context is acquired from the :exemplar: after you clicked the debug button.  I should try this all myself, instead of asking but, I assume if we are debugging in the context of some application, the debug values will be from that context, rather than the exemplar right? I am thinking if the running code is missing some value, it would not be placed in from an exemplar :) 

- Not about exemplars - I noticed you used balance_slot not balanceSlot. It has been a wish of mine for a long time that underscores are accepted as the prefered word separator in naming, rather than camel case :) Is that a accident or a sign of intention? :)

Thanks,
Milan

Gilad Bracha

unread,
Aug 7, 2021, 9:31:33 PM8/7/21
to newspeak...@googlegroups.com
Hi Milan,

On Sat, Aug 7, 2021 at 5:44 PM Milan Zimmermann <milan.zi...@gmail.com> wrote:
Gilad, 

I just watched the videos and finally read this thread. This is really cool. 

Thanks.

- Are the exemplars always extracted from the comment before the " = (..)" section defining the factory constructor, instance method or class method,

Yes. There can in fact be multiple exemplar comments. An exemplar comment is one whose identifer (the name given between colons in the tag at the beginning of the comment) starts with #exemplar. For example, we can define a method #foo:

public foo: x (* :exemplar_1:  foo: 3 *) (* an random comment *)  (:exemplar_2: foo: 'a' *) = (^x)

In that case, the Debug button will provide a menu of the two exemplars .
 
or can the :exemplar: section be in any comment inside the method, factory or class method?

No.   Exemplar comments are just an instance of the general notion of metadata comments. You can have metadata comments everywhere, but there are general rules for what AST node a metadata comment applies to. Exemplar comments must apply to the method as a whole, and must go just before the method body starts (or for classes, before factory body starts) so that they apply to the correct AST nodes. The mirror system looks for metadata  for methods and classes in these places. You can look at the methods #metadata and #parseMetadata in MethodMirror and ClassHeaderMirror, to see how this works; also the class MetadataParsing.

- If one has a class and wants to add an :exemplar: to it properly, one has to be dilligent and add them *on every method that provides instance "inputs"* - constructors, instance and class methods - otherwise evaluations in places that relies on some un-exemplared section would be confusing or incorrect (using nil or something like that?), is that a reasonable assumption?

No, this is not the case. Each exemplar will define bindings, and these will be used to call any other methods independently.

Also, I assume that super factories and methods need to be exemplared for it to fully function. 

No. See above.

Or is there perhaps some tool that checks missing exemplar inputs througout the class definition?

No there isn't, and there is no need.

- Answer to this is probably obvious, but here:  In the video, the debug context is acquired from the :exemplar: after you clicked the debug button.  I should try this all myself, instead of asking but, I assume if we are debugging in the context of some application, the debug values will be from that context, rather than the exemplar right?

Yes. Also if you open an Object inspector, and look at the class in that context, the binding of Self comes from the object being inspected, not from the class exemplar.

I am thinking if the running code is missing some value, it would not be placed in from an exemplar :) 

True.

- Not about exemplars - I noticed you used balance_slot not balanceSlot. It has been a wish of mine for a long time that underscores are accepted as the prefered word separator in naming, rather than camel case :) Is that a accident or a sign of intention? :)

I should be more careful to use consistent conventions.I'm not sure I have a strong position/opinion here.  In any case, _ is legal in identifiers.

And beware, this stuff is still very buggy.

--
Cheers, Gilad

Milan Zimmermann

unread,
Aug 7, 2021, 10:22:36 PM8/7/21
to Newspeak Programming Language
Thanks Gilad. A few notes - essentially notes to myself only except one confirmation ;)  - inline

On Saturday, 7 August 2021 at 18:31:33 UTC-7 Gilad Bracha wrote:
Hi Milan,

On Sat, Aug 7, 2021 at 5:44 PM Milan Zimmermann <milan.zi...@gmail.com> wrote:
Gilad, 

I just watched the videos and finally read this thread. This is really cool. 

Thanks.

- Are the exemplars always extracted from the comment before the " = (..)" section defining the factory constructor, instance method or class method,

Yes. There can in fact be multiple exemplar comments. An exemplar comment is one whose identifer (the name given between colons in the tag at the beginning of the comment) starts with #exemplar. For example, we can define a method #foo:

public foo: x (* :exemplar_1:  foo: 3 *) (* an random comment *)  (:exemplar_2: foo: 'a' *) = (^x)

 public foo: x (* :exemplar_1:  foo: 3 *) (* an random comment *)  (* :exemplar_2: foo: 'a' *) = (^x)


In that case, the Debug button will provide a menu of the two exemplars .

Ah, ok. yes. 
 
or can the :exemplar: section be in any comment inside the method, factory or class method?

No.   Exemplar comments are just an instance of the general notion of metadata comments. You can have metadata comments everywhere, but there are general rules for what AST node a metadata comment applies to. Exemplar comments must apply to the method as a whole, and must go just before the method body starts (or for classes, before factory body starts) so that they apply to the correct AST nodes. The mirror system looks for metadata  for methods and classes in these places. You can look at the methods #metadata and #parseMetadata in MethodMirror and ClassHeaderMirror, to see how this works; also the class MetadataParsing.

Thanks for the context. 

- If one has a class and wants to add an :exemplar: to it properly, one has to be dilligent and add them *on every method that provides instance "inputs"* - constructors, instance and class methods - otherwise evaluations in places that relies on some un-exemplared section would be confusing or incorrect (using nil or something like that?), is that a reasonable assumption?

No, this is not the case. Each exemplar will define bindings, and these will be used to call any other methods independently.

Hmm, so in your video if the exemplar on the factory method 

#balance: b 

was missing, the exemplar instance would not even be shown in the IDE? I was coming from the direction of thinking, if the exemplar

#withdraw: amount 

was there, any evaluation using balance could not have worked. 


Also, I assume that super factories and methods need to be exemplared for it to fully function. 

No. See above.

Or is there perhaps some tool that checks missing exemplar inputs througout the class definition?

No there isn't, and there is no need.

- Answer to this is probably obvious, but here:  In the video, the debug context is acquired from the :exemplar: after you clicked the debug button.  I should try this all myself, instead of asking but, I assume if we are debugging in the context of some application, the debug values will be from that context, rather than the exemplar right?

Yes. Also if you open an Object inspector, and look at the class in that context, the binding of Self comes from the object being inspected, not from the class exemplar.

Ok. I will take a look at that. 


I am thinking if the running code is missing some value, it would not be placed in from an exemplar :) 

True.

- Not about exemplars - I noticed you used balance_slot not balanceSlot. It has been a wish of mine for a long time that underscores are accepted as the prefered word separator in naming, rather than camel case :) Is that a accident or a sign of intention? :)

I should be more careful to use consistent conventions.I'm not sure I have a strong position/opinion here.  In any case, _ is legal in identifiers.

hehe, I know. Could not resist though :) 

And beware, this stuff is still very buggy.

Well I am sure it is good for some basic experiments.  I think you mentioned the server.zip is on the same level as online, so I will use that. (I have on my list next to learn how to build everything)

Thanks for your comments!
Milan


--
Cheers, Gilad

Gilad Bracha

unread,
Aug 7, 2021, 10:30:03 PM8/7/21
to newspeak...@googlegroups.com
On Sat, Aug 7, 2021 at 7:22 PM Milan Zimmermann <milan.zi...@gmail.com> wrote:
Thanks Gilad. A few notes - essentially notes to myself only except one confirmation ;)  - inline

On Saturday, 7 August 2021 at 18:31:33 UTC-7 Gilad Bracha wrote:

- If one has a class and wants to add an :exemplar: to it properly, one has to be dilligent and add them *on every method that provides instance "inputs"* - constructors, instance and class methods - otherwise evaluations in places that relies on some un-exemplared section would be confusing or incorrect (using nil or something like that?), is that a reasonable assumption?

No, this is not the case. Each exemplar will define bindings, and these will be used to call any other methods independently.

Hmm, so in your video if the exemplar on the factory method 

#balance: b 

was missing, the exemplar instance would not even be shown in the IDE?

Exactly. If there isn't an exemplar for self, the method exemplars cannot work. In principle you should get an error message and default to dead code. This is however, an area where things are quite buggy.
 

Yes. Also if you open an Object inspector, and look at the class in that context, the binding of Self comes from the object being inspected, not from the class exemplar.

Ok. I will take a look at that. 


Well I am sure it is good for some basic experiments.  I think you mentioned the server.zip is on the same level as online, so I will use that. (I have on my list next to learn how to build everything)

Oh, thanks for reminding me. I think I forgot to update that. I'll try and do that soon.

--
Cheers, Gilad

Gilad Bracha

unread,
Aug 7, 2021, 10:33:00 PM8/7/21
to newspeak...@googlegroups.com
And I just updated servable.zip. May take a minute or to percolate thru, and then everything should be consistent.
--
Cheers, Gilad

Milan Zimmermann

unread,
Aug 7, 2021, 10:55:24 PM8/7/21
to newspeak...@googlegroups.com
On Sat, Aug 7, 2021 at 7:33 PM Gilad Bracha <gi...@bracha.org> wrote:
And I just updated servable.zip. May take a minute or to percolate thru, and then everything should be consistent.


Ah thanks, that is excellent. I will start using it.

My next step is to learn how to build everything - to not bother you with servable.zip but also to have a better handle of as many things as possible to make myself feel more self sufficient, maybe build the Electron version etc. 

Step by step ... 


--
You received this message because you are subscribed to the Google Groups "Newspeak Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to newspeaklangua...@googlegroups.com.

Gilad Bracha

unread,
Aug 12, 2021, 4:16:36 PM8/12/21
to Newspeak Programming Language
I just published brief blog post about the metadata based exemplar approach:

Gilad Bracha

unread,
Sep 15, 2021, 11:55:45 PM9/15/21
to Newspeak Programming Language
I'll be presenting the exemplar work at the LIVE workshop at SPLASH on October 19th.  I hope to make some improvements by then. Here's the write up I submitted to the workshop. It's work in progress and will continue to evolve. It will not go into the proceedings or anything. When the system is reasonably complete and we have more experience, I may turn it into a full paper.
newspeak-exemplar-ide.pdf

Gilad Bracha

unread,
Oct 21, 2021, 6:52:21 PM10/21/21
to Newspeak Programming Language
Updated version of the exemplar writeup is at http://newspeaklanguage.org/pubs/newspeak-exemplars.pdf.

Milan Zimmermann

unread,
Oct 28, 2021, 6:15:13 PM10/28/21
to Newspeak Programming Language
Thanks for the updated link. FWIW,  I also updated my notes on Newspeak in the following sections: a) Terminology b) Exemplars c) Accessibility

Terminology

Exemplars

Accessibility

I managed to not get much time in the least two months. Almost all of this was done two months ago, except the examples in the accessibility section. So for example the exemplars do not have a link to your PDF but I will add that.

Milan 

Gilad Bracha

unread,
Oct 28, 2021, 8:37:45 PM10/28/21
to newspeak...@googlegroups.com
Thanks Milan. I too have had too little time to work on Newspeak recently.  Things are usually a bit better toward the end of the year, so I hope to finish the exemplar project soon.

You received this message because you are subscribed to a topic in the Google Groups "Newspeak Programming Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/newspeaklanguage/cPG5Q6NOwiA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to newspeaklangua...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/newspeaklanguage/01333d8c-e16b-47c0-b839-ecbbc566660cn%40googlegroups.com.


--
Cheers, Gilad
Reply all
Reply to author
Forward
0 new messages