pocmatos
2019-2-20 09:19:49

@abbyrjones72 that’s great, url?


diego
2019-2-20 09:44:20

URL?


pierre
2019-2-20 10:22:41

@pierre has joined the channel


pierre
2019-2-20 10:26:36

:wave::skin-tone–3: racketeers


hoshom
2019-2-20 10:45:41

How do I make a macro that transforms: (make-thing foo self) to: (define foo (thing #f)) (set-thing-x! foo foo) Assuming thing is (struct thing (x) #:transparent #:mutable)


hoshom
2019-2-20 10:47:31

is it OK to just do syntax->list, replace, and transform back? I’m trying to use syntax-parameterize and failing.


soegaard2
2019-2-20 11:30:27
#lang racket
(require (for-syntax syntax/parse))

(struct thing (x) #:transparent #:mutable)

(define-syntax (create-thing stx)
  (syntax-parse stx
    [(_create-thing id)
     (syntax/loc stx
       (begin
         (define id (thing #f))
         (set-thing-x! id id)))]))

(create-thing foo)
foo

soegaard2
2019-2-20 11:30:42

@hoshom ^


hoshom
2019-2-20 12:35:56

No, it’s only supposed to replace uses of “self” with itself


soegaard2
2019-2-20 12:37:25

So (make-thing foo self) is not the macro call?


hoshom
2019-2-20 12:38:09

it is


hoshom
2019-2-20 12:38:21

but for example if “thing” had 2 fields


hoshom
2019-2-20 12:38:30

i’d do (make-thing 1 self)


hoshom
2019-2-20 12:38:53

the first field in the struct would be 1, but the second, that says self, I want to set! that to itself


soegaard2
2019-2-20 12:39:51

hoshom
2019-2-20 12:39:57

I suppose I should make a function and not a macro though so I’ll just make do


hoshom
2019-2-20 12:40:35

that’s interesting, thanks


d_run
2019-2-20 13:00:51

well well well!


sorawee
2019-2-20 13:02:04

@hoshom

#lang racket

(require (for-syntax racket/function
                     syntax/parse))

(struct thing (x y) #:transparent #:mutable)
(define self (gensym 'self))

(define-syntax (replace stx)
  (syntax-parse stx
    [(_ field id)
     (cond
       [(and (identifier? #'field) (free-identifier=? #'self #'field)) #'id]
       [else #'field])]))

(define-syntax (make-thing stx)
  (syntax-parse stx
    [(_ id:id field ...)
     #'(define id (shared ([id (thing (replace field id) ...)]) id))]))

(make-thing foo 10 self)
(make-thing bar self 20)
(make-thing baz self self)
(make-thing blah 10 20)

foo
bar
baz
blah

;; #0=(thing 10 #0#)
;; #0=(thing #0# 20)
;; #0=(thing #0# #0#)
;; (thing 10 20)

hoshom
2019-2-20 13:16:32

@sorawee That’s neat, that does the trick. Thanks!


sorawee
2019-2-20 13:26:07

Actually, this allows self to be used outside of the macro


sorawee
2019-2-20 13:26:20

This is a version that prohibits it


sorawee
2019-2-20 13:26:23
#lang racket

(require racket/stxparam)

(struct thing (x y) #:transparent #:mutable)

(define-syntax-parameter self
  (λ (stx) (raise-syntax-error (syntax-e stx) "can only be used inside make-thing")))

(define-syntax-rule (make-thing id field ...)
  (define id
    (shared ([x (thing (syntax-parameterize ([self (make-rename-transformer #'x)])
                         field) ...)]) x)))

(make-thing foo 10 self)
(make-thing bar self 20)
(make-thing baz self self)
(make-thing blah 10 20)

foo
bar
baz
blah


abbyrjones72
2019-2-20 13:53:04

abbyrjones72
2019-2-20 13:53:16

it’s very remedial, but I learn slow


jerome.martin.dev
2019-2-20 14:00:53

@abbyrjones72 Well, I’m glad you found Lisp on your path. Not every programmer stops by and try to learn such languages because they look so “weird” and “different” and “old”. SICP was a fundamental read for me too. With Racket I’m home, so, welcome there!


abbyrjones72
2019-2-20 14:02:07

Ty so much :slightly_smiling_face:


abbyrjones72
2019-2-20 14:05:13

I guess the good thing about being unemployed (at least from programming) is that I don’t have to divide my loyalties between what I want to learn and what I have to learn. I seriously doubt I will ever work in LISP professionally, but in this stage of my life, as I formulate research in healthcare, adding to the body of knowledge is an important, fulfilling venture in itself. I hope that I can contribute something to at some point.


diego
2019-2-20 15:42:08

@abbyrjones72 Very nice blog so far! I look forward to more of it.


abbyrjones72
2019-2-20 15:42:47

I posted a new one today. If you get bored and want to check my work, please don’t hesitate to correct me.


abbyrjones72
2019-2-20 15:42:56

and ty :slightly_smiling_face:


diego
2019-2-20 15:45:01

I have been programming since I was 10, and although I don’t do it for my job anymore (I’ve turned into an architect and manager, sigh), I still enjoy and do it for fun at home. One thing you might try for programming exercises: https://adventofcode.com - it’s no longer “live” but the exercises (also from previous years) are available. I participated for the first time this year (didn’t finish), and I made it a point of using Racket for the exercises, it’s a great way to practice.


benjamin.clos
2019-2-20 15:48:14

i’ve been working through the http://exercism.io\|exercism.io racket track, I’ve found it’s a good way to jump into the ecosystem myself.


benjamin.clos
2019-2-20 15:48:40

Also makes it nice there is now a mentor system, there are a few people that have been really nice to point some stuff out


abbyrjones72
2019-2-20 15:48:43

I will definitely try both sites.


benjamin.clos
2019-2-20 15:48:55

(also very new to Racket, as in just started a week ago)


abbyrjones72
2019-2-20 15:55:46

I am new to Racket, LISP, and computer science in general. Little to no math background, but it is my hope to answer every question in the SICP to improve myself.


andreiformiga
2019-2-20 16:08:51

last time I’ve seen it the exercism track for Racket needed some work. I submitted a couple of PRs improving some of the exercises but they did take a long time to be merged


benjamin.clos
2019-2-20 16:09:51

Hmm, I’m only a few exercises in, we’ll see once I get further along. It does gate you a good amount now if you ask for feedback


andreiformiga
2019-2-20 16:10:06

@benjamin.clos if you have any trouble you can ask about it here


d_run
2019-2-20 16:10:39

Fellow Apple IIe learner here. Really glad to see posts from other folks who took roundabout or non-traditional paths into computing. Keep writing!


benjamin.clos
2019-2-20 16:12:12

Much appreciated. :slightly_smiling_face: will probably be taking that offer up once I get to some of harder data manipulation ones.


abbyrjones72
2019-2-20 17:07:35

I posted blog 3 just a few minutes. As always, enjoy and rip it apart. I’m here to learn :slightly_smiling_face:



blerner
2019-2-20 17:56:04

Is there a scribble package akin to mathpartir, for typesetting inference rules and (fairly simple) derivation trees? For context, I’m typesetting lecture notes that will run with MathJax, so I can use any basic LaTeX stuff but not any packages…


githree
2019-2-20 18:05:47

@abbyrjones72 nice blog posts! Just in case - there is sicp package available that gives more support/compatibility with SICP: https://docs.racket-lang.org/sicp-manual/


abbyrjones72
2019-2-20 18:29:38

Oh my goodness, this is fantastic. Thank you @githree. I am still only halfway through Chapter 1, but this is so good to know and I will add this to my blogs.


githree
2019-2-20 18:30:51

That’s the power of Racket :slightly_smiling_face:


bkovitz
2019-2-20 18:34:08

@abbyrjones72 Would you like to see my solution to the sum-of-squares problem? It might be interesting because it’s very different, and it applies a couple of those often-reusable idioms that make programming require less thought.


abbyrjones72
2019-2-20 18:51:01

Sure!


abbyrjones72
2019-2-20 18:51:29

I will also be happy to include that alternate solution in my blog. I’m all about more efficient solutions.


bkovitz
2019-2-20 19:06:26

This might look like a mess, and indeed @soegaard2’s solution is much more elegant and efficient. But it popped into my head instantly, just applying habitual ways of mentally framing it that have been helpful many times before. I would not have naturally hit on this approach if it weren’t for other people having shown me these tricks long ago.


abbyrjones72
2019-2-20 19:08:12

I think I need to add both of your solutions to the blog so I can learn from then. TY!


d_run
2019-2-20 19:08:39

I always love to see how other people solve things, i almost always learn something


bkovitz
2019-2-20 19:10:07

If you’re only just getting accustomed to passing arguments, this solution is probably way too much. When I first saw this sort of thing, I thought it was too tricky. I think it’s pretty typical of pure-functional programming (I could be wrong: I can’t speak with authority about that), and it’s gets easier to read with time. But right now, it might be best to save someplace and look at again later.


abbyrjones72
2019-2-20 19:12:52

It is way out of my league, but at the moment. If it’s too hard for me now, then that is good.


benjamin.clos
2019-2-20 19:13:05

heh, that was the problem I worked on last with exercism


benjamin.clos
2019-2-20 19:15:48

though, the scope was different


bkovitz
2019-2-20 19:21:46

@abbyrjones72 OK, it’s probably like looking a few chapters ahead in a book teaching a foreign language. I thought of it because of your observation that the problem was so hard, it seemed discouraging. After a while, problems like that will “light up” familiar, friendly ways of looking at them, which make them easy.


bkovitz
2019-2-20 19:22:39

(They also create new blind spots: I totally did not see @soegaard2’s solution. That one exploits algebra—the problem domain rather than programming tricks!)


abbyrjones72
2019-2-20 19:23:03

I like hard problems because it means I am learning something.


bkovitz
2019-2-20 19:23:09

@benjamin.clos Thanks for telling me about http://exercism.io\|exercism.io! I just signed up for it; now waiting for the email…


abbyrjones72
2019-2-20 20:08:44

just downloaded Exercism lesson one.


pierre
2019-2-20 20:36:11

look who’s there


pierre
2019-2-20 20:36:21

I took the time to register here, at last


d_run
2019-2-20 20:54:05

:clap:


bill_temps
2019-2-20 21:30:41

@bkovitz That strikes me as a very SQL-ish way of solving the problem. I hope you don’t find that insulting.


pierre
2019-2-20 21:32:37

is it possible to access a struct field value from its name?


samth
2019-2-20 21:51:50

@pierre no, not really


plragde
2019-2-20 22:30:29

After some poking around (for a course on logic and computation), I just went with \frac, slightly tweaked. That’s what mathpartir uses at its heart, anyway.


blerner
2019-2-20 22:41:25

true enough, but I was hoping someone had define-syntax’ed some nicer wrappers around that, so that it felt nicer to write in Racket :slightly_smiling_face:


bkovitz
2019-2-21 00:49:14

@bill_temps Not at all. I’d love to see another solution.


bkovitz
2019-2-21 01:27:01

@bill_temps Say, would it be fair to say that a lot of pure-functional programming is SQL-ish? Especially the “map–filter” style?


hoshom
2019-2-21 03:51:32

Cool, thanks! When I tried this using syntax parameters, shared is what I was missing. I guess I still have a long way to go to get a feel of how bindings really work.


ruyvalle
2019-2-21 04:27:56

@ruyvalle has joined the channel