zenspider
2018-5-22 08:13:58

I always get that backwards. In my head it is “I want to take N items from X” and I can’t fix that. Honestly, I think my version should be right. More curry friendly and it just makes loads more sense to me.


zenspider
2018-5-22 08:14:25

Glad you got things sorted out.


mark.warren
2018-5-22 08:17:22

I was wondering if there was any general advice on when to use different data structures (hash, struct class). As a Java programmer I obviously have no choice but to use classes, but Scheme gives me more choice. Any thoughts?


greg
2018-5-22 13:08:44

@mark.warren I think it’s hard to give general advice. It depends on what you’re trying to accomplish and what you prefer.


greg
2018-5-22 13:08:51

For example racket/class is a comprehensive class/OOP system. I’ve hardly used it in ~7 years of using Racket. Why? Because previously I spent many years doing GUI OOP C++, and wanted to learn different things using Racket. However, if I had to write a desktop GUI app, I would probably happily use racket/gui and racket/class.


mark.warren
2018-5-22 13:11:11

@greg I thought it might be a bit too vague a question. I guess I’m still trying to wrap my head around trying to keep data immutable but at the same time still have state.


samth
2018-5-22 13:11:17

@mark.warren I would use hash tables in roughly the same places you’d use a hash table in java


greg
2018-5-22 13:11:24

I can also tell you that, unlike Clojure where people tend to use maps a.k.a. hash-tables a lot, in Racket people tend to use structs more. However it’s Racket so you could use hash-tables, and even create syntax for things like {} initialization and map application etc.


greg
2018-5-22 13:11:55

Oops didn’t see samth while typing that. Agree.


samth
2018-5-22 13:12:40

and I would use structs for basically all data that you’d create a class for in Java, but if the class wouldn’t have any real “data” in it, then you just don’t create the class and have functions instead


mark.warren
2018-5-22 13:17:04

@greg @samth Thanks, I’m probably over analysing instead of just doing stuff and seeing where I get.


greg
2018-5-22 13:18:03

@mark.warren > still trying to wrap my head around trying to keep data immutable but at the same time still have state. Yes. Coming from C++, I found this — functional, immutable — weirder than “all the parentheses”. e.g. I need to loop through something. What do you mean I can’t mutate the index or an accumulator variable? How does it even work?


mark.warren
2018-5-22 13:19:19

@greg Yep that definitely threw me.


greg
2018-5-22 13:19:39

The short answer is that, functions don’t change the original thing. Instead they return a copy of the original, that has the changes.


greg
2018-5-22 13:20:18

Also “loops” in Racket can be recursively calling a function on successive elements of a list or whatever.


mark.warren
2018-5-22 13:21:36

That’s part of what my head can’t get, usually (in Java etc.) copies are bad due to memory allocation and garbage collection.


greg
2018-5-22 13:23:01

Total copies are still bad for those reasons in Racket. :slightly_smiling_face: However I’d suggest, don’t worry about that at first. Pretend it’s not a big deal. Suspend your disbelief for a few days/weeks while you learn.


andreiformiga
2018-5-22 13:23:08

first think about how to best solve the problem. worry about optimization later


greg
2018-5-22 13:23:16

Jinx. :slightly_smiling_face:


mark.warren
2018-5-22 13:23:40

Always good advice.


andreiformiga
2018-5-22 13:23:53

copying can be an issue. I once wrote a bf interpreter in Haskell using pure arrays and it was a disaster, performance-wise. later I used a monadic array to get updates in-place


andreiformiga
2018-5-22 13:24:16

in racket you can have mutation and side effects when you need them, but it’s best to try to be “functional-first” and change later if needed


greg
2018-5-22 13:24:26

Yep. Later you can learn about how much that matters, as well as how/when things use structural sharing, and how you can handle this.


greg
2018-5-22 13:25:27

Also BTW Racket is not “zealous” about this. You can set! variables and struct fields if you really want to. And there are mutable as well as immutable variations of hash-tables, for instance.


greg
2018-5-22 13:26:12

But. It’s more typical to avoid that unless it’s really truly necessary.


greg
2018-5-22 13:26:39

Also, any mutation is often an implementation detail, wrapped in a functional outer layer.


mark.warren
2018-5-22 13:27:27

Sure, it’s about getting my head out of the object mind set.


greg
2018-5-22 13:28:33

So if you’ve been in Java land for awhile, let the pendulum swing all the way to the opposite side for awhile. Then eventually it can settle wherever in the middle makes sense for you. :slightly_smiling_face: Good luck!


mark.warren
2018-5-22 13:29:15

Cheers


ghoetker
2018-5-22 22:33:29

I made a thing!

It’s a “toy” thing, but I wanted to mention it because it never would have been possible without help from many of the fine folks in this group. Thank you, thank you, thank you! It’s also perhaps an inspiration for other beginners, showing what Racket allows even an amateur to accomplish in relatively few lines of code. I’d be happy to share the code if anyone wants to see it, but be warned that it will probably cause experienced Racketeers actual physical pain.

I hope it’s okay that I’ve attached short demo video. As background, most scholarly publications have a Document Object Identifier (DOI), which provides a unique identifier useful for bibliography management, etc. Older papers were assigned DOIs retroactively, which means I often need to look up their DOI using words from the title, author’s name, etc. Searches often return multiple potential matches to choose from.

Now, there are websites for doing so. But, they require multiple clicks and copying text to extract the required information. Where’s the fun in that, especially if one if dodging real work? Thus, I created a small app that will search for DOIs (defaulting to whatever information was in the clipboard when launched), present a list of potential matches and place the DOI of the chosen article in the clipboard.

Once I got past a few mental roadblocks (with help from here), the project was surprisingly easy and even fun. Doing it taught me a lot that will go into more serious work. Racket rocks! Thanks all.


greg
2018-5-22 23:40:57

@ghoetker Nice! :tada: