
@steveh2009 Hi Steve, sorry your question got missed a bit. I found class initialisation a bit confusing at the start, but init-field
as I understand it only creates a field and doesn’t assign anything to it, in order to assign an initialisation value to it you need to do something like (init-field [(internal-broker broker)])
, where internal-broker is the field name and broker is the initialisation parameter name, does that make sense?

Please anyone correct me if I am wrong.

submodules ?

@jgeddes has joined the channel

I think s/he’s trying to create a new object with broker-object
as the field value.

@steveh2009: this works fine for me:
#lang racket
(define priceladder%
(class object%
(super-new)
(init-field broker)))
(new priceladder% [broker 1])

There shouldn’t be any problem. Can you provide the whole code that triggers the error?

@sorawee I’m still trying to wrap my head around object initialisation, I don’t do enough of it to be certain about each initialisation method.

The handin server’s dependency on GUI functionality is annoying. The simplest solution may be xvfb-run racket -l handin-server
.

Thanks. I removed the compile subdir and it worked. Didn’t work trying to just “Run” through the separate files until I got to the main one which kicked it off. I made a much smaller example, passing the same object through 2 levels (priceladder% has gui controls wrapping a plcanvas% class that does all of the grid manipulations). I noticed that error can be triggered on a misspelling but this wasn’t the case in the full code. I used init-field with no default value b/c the broker object has to be passed in for it all to work. No namespace collisions by the field name and name of the object being the same.

Thanks!! BTW, super useful package. I am excited, but hesitant, to use it in my first Racket course. Do you have any tips on setting up a service to run the server? Or are there any gotchas that you are aware of? Thanks in advance.

You are right to be wary. :slightly_smiling_face: The handin server works great for some and not great for others, so be sure to field test it as much as possible before committing to using it. I normally run the server in a screen
session, which is the easiest way to keep it running on the host server and to check in from time to time. Also, I usually have to restart the server once per semester for an 80-student class writing plait
programs (as opposed to the the HtDP languages).

Thanks!! Much appreciated.

In DrRacket, if I’ve just evaluated something at the REPL and am now trying to evaluate something that needs to use the previous result, is there a special variable I can reference for this? (At the Python REPL this would be _
, for example.)

@jab Not out of the box. But it wouldn’t surprise me, if someone had made a plugin for that.

You can use esc-p to get the previous expression.

Yeah, I found ESC-P documented at https://docs.racket-lang.org/drracket/interactions-window.html but not this

Googling around for this hasn’t helped yet

Is there a way to do that in xrepl?


Nice! Is there some way to get this to work in DrRacket?

Context: I’m currently taking http://dabeaz.com/sicp.html with a bunch of other new Racketeers and we’re missing this feature

I think you can just add (require xrepl)
to your program.

(Dave wants to know the answer too:)

> (require xrepl)
> (+ 1 2)
3
> ^
; ^: undefined;
; cannot reference an identifier before its definition
; [,bt for context]
> (display ^)
; ^: undefined;
; cannot reference an identifier before its definition
; [,bt for context]

(That was copy/pasted from the DrRacket interactions window - should it have worked?)

I’ll try.

Hmm. Okay. It works in the terminal: mbp:tests soegaard$ racket
Welcome to Racket v7.3.
> (require xrepl)
> (+ 1 2)
3
> ^
3
> $1

It doesn’t work in the DrRacket repl.

DrRacket has its own repl - but maybe there is a way?

We’re breaking for lunch now but will check back here after - thanks so much!

@jab Btw when/if you come to the chapter with pictures in SICP, then remember that there is a new implementation of the picture language available - it has more features than described in the book. See this file (and examples at the bottom): https://github.com/sicp-lang/sicp/blob/master/sicp-pict/main.rkt

Hack of the day:

What’s going on here?

First read-eval-print-loop
sets up a repl.

Since it needs to evaluate expressions, it needs a namespace.

The value of (current-namespace)
can’t be used, since it doesn’t contain the bindings inside the module.

So to the (variable-reference->namespace (#%variable-reference))
gets the namespace “inside” the module.

I found the How to Design Programs SE at Goodwill for .99 and started using it, only to find no that there are no explanations of using ‘require’. Is it just implied or are the libs handled by switching to the lang in the chooser? Can’t seem to draw a circle to save me life lol

Is that a cure for the problems with the top-level reply that Alexis mentioned a couple of days ago.(With the long list of references)

Can’t find the dicussion. What was the date and channel?


Sorry it was on the mailing list and it was 3 weeks ago :grimacing:

Time flies :slightly_smiling_face:

I think Alexis wanted a way to add a submodule to an already instantiated module.

I don’t think that possible.

maybe racket2:grin:

@abbyrjones72 In DrRacket: Use the menu “Language” and the menu item “Choose Language”. Then pick one of the teaching languages.

thanks for explainign oyur code to me.

Now in the …mumble… menu you can choose “Add TeachPack”.

You now get a list of available teachpacks among them an image teachpack.

The teackpacks are listed here:


Yeah, I chose Htdp section, but I will explore the teachpacks as well.

that worked. Thank you @abmclin

ug

not me who gave the advice

yeah i know that was weird

lol

ty @soegaard2

np

Thanks @soegaard2, got that to work. Looks like this REPL doesn’t support all the features of the default one in the interactions window though. E.g. The Cmd+/ keyboard shortcut to show completions doesn’t work. So I’m not sure it’s worth it. I guess one of us should file a feature request in the Racket issue tracker?

Yeah. Just a hack.

Do you happen to know if there is an equivalent of Python’s dir()
function?

what does it do?

I.e. given an object, list its attributes.

where object means “some value” or “an object from an object/class system” ?


In Python, everything is an object, so you can pass primitives like 42
and it still works.


(Ellipses mine.)

I think the closest is “describe”.


But I think there is a newer, similar package that allows you to examine a value graphically.

In either case though this isn’t a Racket “built-in” nor is it in Racket’s “standard library” (using Python terms, not sure they’re the same), so you have to raco package install
something third-party?

yes

Surprising, thanks! The graphical inspect package sounds interesting


No. That’s not it. I can’t remember the name.

Thanks anyway. Do you know if Racket has an equivalent to Python’s globals()
function, which provides all the globally-available bindings that are available?


Yes. It’s not very useful though. Let me find an example.

Oh, why’s that? And thank you for looking!

Well, I am curious - what do you use it for in Python?

Try this in the repl:

(namespace-mapped-symbols (current-namespace))

It will give you all names bound in the current namespace.

That is all the names that your current language provides with the names that you have imported (using require).

Thanks @soegaard2, I see that printed a list out. Python’s globals()
gives you the mapping from names to values. This is useful because you can do dynamic things like this:


With the above, I was prompted to enter something, and entered that “x” you see there before it then looked up that binding and printed “foo”.
Does Racket have an out-of-the-box way to get the mapping of bound names to values in the namespace so you can look up (possibly dynamically constructed) names?

In Racket can use eval
to evaluate expressions.

In principle (eval 'x)
will give you the value of x.

You can use eval
in Python too but it’s not preferred for this since it’s much more powerful than necessary. (I.e. you wouldn’t want to use it with untrusted, user-supplied input as in my example above.)

In most cases you need to set up which namespace (think which set of globals) you are using.

Thanks

Well, you can use (namespace-variable-value ...)
instead. It directly makes a lookup in the namespace.

nice, thanks!

But … for a program that with untrusted user input - I think using an explicit hash table is better.

(a dict in python, I believe)

More just trying to figure out idiomatic ways of inspecting your current environment in Racket.


Food for thought.