mark.warren
2019-7-29 07:03:26

@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?


mark.warren
2019-7-29 07:03:59

Please anyone correct me if I am wrong.


spdegabrielle
2019-7-29 08:07:04

submodules ?


jgeddes
2019-7-29 08:51:27

@jgeddes has joined the channel


sorawee
2019-7-29 09:54:11

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


sorawee
2019-7-29 09:54:30

@steveh2009: this works fine for me:

#lang racket

(define priceladder%
  (class object%
    (super-new)
    (init-field broker)))

(new priceladder% [broker 1])

sorawee
2019-7-29 09:56:02

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


mark.warren
2019-7-29 10:00:43

@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.


mflatt
2019-7-29 12:42:34

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


steveh2009
2019-7-29 12:43:02

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.


bytezen
2019-7-29 14:14:16

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.


mflatt
2019-7-29 14:19:53

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).


bytezen
2019-7-29 14:37:08

Thanks!! Much appreciated.


jab
2019-7-29 17:50:39

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.)


soegaard2
2019-7-29 17:52:43

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


soegaard2
2019-7-29 17:52:58

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


jab
2019-7-29 17:53:14

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


jab
2019-7-29 17:53:22

Googling around for this hasn’t helped yet


samdphillips
2019-7-29 17:53:49

Is there a way to do that in xrepl?



jab
2019-7-29 17:55:11

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


jab
2019-7-29 17:55:18

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


soegaard2
2019-7-29 17:55:30

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


jab
2019-7-29 17:55:31

(Dave wants to know the answer too:)


jab
2019-7-29 17:56:06
> (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]

jab
2019-7-29 17:56:51

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


soegaard2
2019-7-29 17:57:07

I’ll try.


soegaard2
2019-7-29 17:59:49

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


soegaard2
2019-7-29 18:00:00

It doesn’t work in the DrRacket repl.


soegaard2
2019-7-29 18:00:35

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


jab
2019-7-29 18:02:09

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


soegaard2
2019-7-29 18:08:03

@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


soegaard2
2019-7-29 18:18:28

Hack of the day:


spdegabrielle
2019-7-29 18:38:37

What’s going on here?


soegaard2
2019-7-29 18:52:16

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


soegaard2
2019-7-29 18:52:30

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


soegaard2
2019-7-29 18:53:10

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


soegaard2
2019-7-29 18:53:55

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


abbyrjones72
2019-7-29 19:02:12

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


spdegabrielle
2019-7-29 19:03:21

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)


soegaard2
2019-7-29 19:06:22

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



spdegabrielle
2019-7-29 19:09:16

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


soegaard2
2019-7-29 19:09:38

Time flies :slightly_smiling_face:


soegaard2
2019-7-29 19:12:24

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


soegaard2
2019-7-29 19:12:32

I don’t think that possible.


spdegabrielle
2019-7-29 19:13:08

maybe racket2:grin:


soegaard2
2019-7-29 19:13:24

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


spdegabrielle
2019-7-29 19:13:26

thanks for explainign oyur code to me.


soegaard2
2019-7-29 19:13:46

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


soegaard2
2019-7-29 19:14:34

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


soegaard2
2019-7-29 19:15:35

The teackpacks are listed here:



abbyrjones72
2019-7-29 19:17:26

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


abbyrjones72
2019-7-29 19:18:14

that worked. Thank you @abmclin


abbyrjones72
2019-7-29 19:18:23

ug


abmclin
2019-7-29 19:18:33

not me who gave the advice


abbyrjones72
2019-7-29 19:18:38

yeah i know that was weird


abbyrjones72
2019-7-29 19:18:42

lol


abbyrjones72
2019-7-29 19:18:54

ty @soegaard2


soegaard2
2019-7-29 19:19:06

np


jab
2019-7-29 21:15:19

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?


soegaard2
2019-7-29 21:16:24

Yeah. Just a hack.


jab
2019-7-29 21:18:34

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


soegaard2
2019-7-29 21:18:49

what does it do?


jab
2019-7-29 21:18:50

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


soegaard2
2019-7-29 21:19:30

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


jab
2019-7-29 21:20:12

jab
2019-7-29 21:20:33

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


jab
2019-7-29 21:21:12

jab
2019-7-29 21:21:19

(Ellipses mine.)


soegaard2
2019-7-29 21:21:37

I think the closest is “describe”.



soegaard2
2019-7-29 21:22:16

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


jab
2019-7-29 21:23:13

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?


soegaard2
2019-7-29 21:23:27

yes


jab
2019-7-29 21:23:51

Surprising, thanks! The graphical inspect package sounds interesting



soegaard2
2019-7-29 21:24:39

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


jab
2019-7-29 21:25:44

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?


jab
2019-7-29 21:26:27

soegaard2
2019-7-29 21:27:00

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


jab
2019-7-29 21:27:28

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


soegaard2
2019-7-29 21:28:35

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


soegaard2
2019-7-29 21:29:31

Try this in the repl:


soegaard2
2019-7-29 21:29:46

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


soegaard2
2019-7-29 21:30:07

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


soegaard2
2019-7-29 21:31:10

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


jab
2019-7-29 21:31:12

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:


jab
2019-7-29 21:32:24

jab
2019-7-29 21:33:41

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?


soegaard2
2019-7-29 21:35:03

In Racket can use eval to evaluate expressions.


soegaard2
2019-7-29 21:35:25

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


jab
2019-7-29 21:35:53

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.)


soegaard2
2019-7-29 21:35:54

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


jab
2019-7-29 21:36:50

Thanks


soegaard2
2019-7-29 21:37:09

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


jab
2019-7-29 21:37:49

nice, thanks!


soegaard2
2019-7-29 21:37:55

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


soegaard2
2019-7-29 21:38:10

(a dict in python, I believe)


jab
2019-7-29 21:38:51

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



soegaard2
2019-7-29 21:39:19

Food for thought.