fractalide / fractalide

Reusable Reproducible Composable Software

Home Page:http://fractalide.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

clacke opened this issue · comments

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.

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

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

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

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)

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.

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

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.

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.

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.

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.