Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: define-agent: We always want to define the 'agt symbol #217

Closed
clacke opened this issue May 28, 2018 · 10 comments
Closed

Problem: define-agent: We always want to define the 'agt symbol #217

clacke opened this issue May 28, 2018 · 10 comments

Comments

@clacke
Copy link
Member

clacke commented May 28, 2018

We are repeating ourselves with (define agt (define-agent, as the agent loader is always looking for the agt symbol.

Solution: define-agent or some other form includes the (define agt bit.

@dmichiels
Copy link
Contributor

I comment here, but it concerns #216 also.

You are right we can clean a little the agent declaration, but I'm not sure to go as far as you describe in #216.

I achieve this result to defining an agent (it is a complete file):

#lang racket

(require fractalide/modules/rkt/rkt-fbp/agent)

(define-agent
  #:input '("a" "b")
  #:output '("out")
  ((input output input-array output-array)
   (define a (recv (input "a")))
   (define b (recv (input "b")))
   (send (output "out") (nand a b))))

I don't think it is possible to get rid of the lambda arguments declaration... Do you have an example were there is argument in a "finish-close like"?

@sjmackenzie
Copy link
Member

sjmackenzie commented May 29, 2018

How about this?:

#lang racket

(require fractalide/modules/rkt/rkt-fbp/agent)

(define-agent
  #:input '("a" "b")
  #:output '("out")
  #:fun input output input-array output-array
   ((define a (recv (input "a")))
   (define b (recv (input "b")))
   (send (output "out") (nand a b))))

@dmichiels
Copy link
Contributor

feasible, but I don't find it is really "racket style".
perhaps we can just keep the lambdakeyword?

#lang racket

(require fractalide/modules/rkt/rkt-fbp/agent)

(define-agent
  #:input '("a" "b")
  #:output '("out")
  (lambda (input output input-array output-array)
   (define a (recv (input "a")))
   (define b (recv (input "b")))
   (send (output "out") (nand a b))))

@sjmackenzie
Copy link
Member

If you look at the examples given in #216 it seems to be idiomatic racket. @mfelleisen could you weigh in on whether this is idiomatic racket please? (namely the body immediately following the #fun attribute)

@clacke
Copy link
Member Author

clacke commented May 29, 2018

Ok, so if I understand correctly, your concern here is that explicit is better than implicit, and it seems non-idiomatic to have input output input-array output-array just appear magically for the benefit of the body, but not being mentioned anywhere in the visible syntax?

I think it should be ok to offer a keyword for overriding them, but allowing them to have their usual names as defaults. After all, we're providing "acc" and "option" implicitly, so we're already down that road for the purpose of conciseness.

@dmichiels
Copy link
Contributor

my real point is that I didn't achieve to write a macro to provide them implicitly... Otherwise, I think it's ok to be implicit.

Here is my actual macro :

(define-syntax (define-agent3 stx)
  (syntax-case stx ()
    [(_ args ... (proc-args body ...))
     #'(begin
         (provide agt)
         (define agt (define-agent
                       args ...
                       #:proc (lambda proc-args
                         body ...)))
         )
     ]))

But I didn't achieve to incorporate the arguments myself...

@sjmackenzie
Copy link
Member

sjmackenzie commented May 29, 2018

Maybe that's not such a bad idea to make the arguments input output input-array output-array implicit (just as the acc and option. In the definition we are declaring the ports i.e.:

  #:input '("a" "b")
  #:output '("out")

So one could infer that (recv (input "a")) is derived from #:input '("a" "b").

Shall we try can get higher powers to help us make those arguments implicit.
Maybe @lexi-lambda might know how to do it?

@dmichiels I can't seem to find that macro you posted, this is the nearest one I could find.

(define-syntax node
(lambda (stx)
(syntax-case stx ()
[(_ name ${type})
#'(let ([t (syntax->string #'(type))])
(g-agent name (string-append "${" t "}")))]
[(_ name type)
#'(g-agent name type)]
)))

EDIT: ah I see, you tried to create the macro, but it didn't work, so didn't use it.

@dmichiels
Copy link
Contributor

Yes, the macro I posted is a WIP, doesn't work yet. But it allows to build agent as I posted in the second comment of this thread.

@dmichiels
Copy link
Contributor

I achieve this :

#lang racket

(require fractalide/modules/rkt/rkt-fbp/agent)

(define-agent
  #:input '("a" "b")
  #:output '("out")
  (fun
     (define a (recv (input "a")))
     (define b (recv (input "b")))
     (send (output "out") (nand a b))))

I will make a PR as soon as I refactor all our nodes.

@clacke
Copy link
Member Author

clacke commented May 30, 2018

Awesome! I'll dig into it again later, have a look at how (command-line) does it, and see if I can shave off the (fun as well.

clacke added a commit to clacke/fractalide that referenced this issue Aug 30, 2018
There are several tricksy things about this. One is that adding these
symbols in the caller's namespace is unhygienic, so Racket works hard
to prevent it. The workaround that 'fun' used with datum->syntax and
creating the names outside the (syntax) forms is the only way.

The other is the keyword arguments. To cleanly pick out the body and
the keyword arguments, and not need define-agent-priv, syntax-parse
is necessary.

Solution: Implement new define-agent, merge define-agent-priv and fun.

 - Retain 'fun' as basically a noop until it has been removed from the
   codebase.
 - Remove #:proc as it is not used anywhere.

Closes the discussion in fractalide#217
clacke added a commit to clacke/fractalide that referenced this issue Aug 30, 2018
There are two tricky things about this:

 - Adding these symbols in the caller's namespace is unhygienic, so
   Racket works hard to prevent it. The workaround that `fun` used
   with `datum->syntax` and creating the names outside the `(syntax)`
   forms is the only way.
 - The keyword arguments. To cleanly pick out the body and the keyword
   arguments, and not need `define-agent-priv`, `syntax-parse` is
   necessary.

Solution: Merge `define-agent-priv` and `fun` into new `define-agent`.

 - Remove `fun` from the codebase.
 - Remove `#:proc` as it is not used anywhere.

Closes the discussion in fractalide#217
clacke added a commit to clacke/fractalide that referenced this issue Aug 30, 2018
There are two tricky things about this:

 - Adding these symbols in the caller's namespace is unhygienic, so
   Racket works hard to prevent it. The workaround that `fun` used
   with `datum->syntax` and creating the names outside the `(syntax)`
   forms is the only way.
 - The keyword arguments. To cleanly pick out the body and the keyword
   arguments, and not need `define-agent-priv`, `syntax-parse` is
   necessary.

Solution: Merge `define-agent-priv` and `fun` into new `define-agent`.

 - Retain `fun` as a noop and remove it from the codebase in a
   separate commit.
 - Remove `#:proc` as it is not used anywhere.

Closes the discussion in fractalide#217
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants