[Cuis-dev] question about Compiler evaluate:

Boris Shingarov shingarov at labware.com
Mon Jan 27 03:40:51 PST 2025


You may also find interesting
https://github.com/shingarov/MachineArithmetic/blob/pure-z3/src/Refinements/DecidableRefinement.class.st#L45

and
https://github.com/shingarov/MachineArithmetic/blob/pure-z3/src/Z3/Z3Node.class.st#L207

What this code does is basically Lisp's dynamically-scoped "earmuff
variables".  You give something like 'a+1' to the Smalltalk compiler
in a context where 'a' is undefined and instead of blowing up it
creates a dynamically-scoped expression (in the first case, a
MessageSend of +1 to a "Cosa" i.e. the undefined variable 'a').
One could then finalize the evaluation once 'a' becomes known.
(In our usage, we normally go one intermediate step, once we know
that 'a' is, say, an integer (by Hindley-Milner inference), we can
compute a little bit more and replace the MessageSend by a Z3Node,
which still contains the symbol 'a' as unknown.  This last part
is not essential to your question, I am telling you this just
so #inThisEnvironment doesn't puzzle you by its receiver).


On Fri, Jan 17, 2025 at 04:50:22PM -0600, Mark Volkmann via Cuis-dev wrote:
> Thanks! That allows me to avoid writing an error message to the Transcript.
> The other thing I want to do is get the error message ("x is Undeclared" in
> this case) so I can display it in my UI.
> Do you know how I can get that?
> I don't see that in any of the instance variables associated with either
> exception object.
> 
> On Fri, Jan 17, 2025 at 12:46 PM Weslleymberg Lisboa via Cuis-dev <
> cuis-dev at lists.cuis.st> wrote:
> 
> > Hi, Mark
> >
> > I found 'is Undeclared' in UndeclaredVariableWarning>>defaultAction
> > which seems to match what you see in the transcript.
> >
> > I was able to get rid of the transcript error message by doing:
> >
> > expression := '1 + x'.
> > [ Compiler evaluate: expression ] on: UndeclaredVariableWarning do: [:ex
> > | ex resume: false] on: Error do: [:ex | ex inspect ]
> >
> > To give a little context, I searched for references to the class
> > UndeclaredVariableWarning. One of the results was Encoder>>#undeclared:
> > where the comments mention how to disable the warning.
> >
> > Em 17/01/2025 09:40, Mark Volkmann via Cuis-dev escreveu:
> > > In a Workspace, if I "Do It" the first expression below and "Print It"
> > > the second expression, it prints 3 as expected.
> > >
> > > expression := '1 + 2'.
> > > [ Compiler evaluate: expression ] on: Error do: [ :ex | ex inspect ].
> > >
> > > Now if I change the 2 in expression to x and repeat, it prints
> > > the following:
> > >
> > > MessageNotUnderstood: UndefinedObject>>adaptToNumber:andSend:
> > >
> > > It also writes the following to the Transcript:
> > >
> > > UndefinedObject>>DoIt (x is Undeclared)
> > >
> > > Looking in the Inspect window I see that none of the instance variables
> > > contain "x is Undeclared". I really want to get that string. I've
> > > searched the Compiler methods and haven't found a way to do this. Does
> > > anyone know how I could access that error message?
> > >
> > > I'd also like to prevent the error message from being written to the
> > > Transcript so I can completely handle it in my code.
> > >
> > > --
> > > R. Mark Volkmann
> > > Object Computing, Inc.
> > >
> >
> > --
> > Wéslleymberg Lisboa
> > Graduado em Sistemas de Informação
> > Docente no IFFluminense - Campus Itaboraí
> >
> > --
> > Cuis-dev mailing list
> > Cuis-dev at lists.cuis.st
> > https://lists.cuis.st/mailman/listinfo/cuis-dev
> >
> 
> 
> -- 
> R. Mark Volkmann
> Object Computing, Inc.

> -- 
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev



More information about the Cuis-dev mailing list