Arc Forumnew | comments | leaders | submit | cooldude127's commentslogin
3 points by cooldude127 6635 days ago | link | parent | on: premature optimizations in Arc

they should be separate just in case someone has another desire to use the self symbol for something. if someone uses if, they don't expect any symbols to be shadowed. if they use aif, they know what to expect.

-----

1 point by binx 6635 days ago | link

In OO languages, methods implicitly bind self and the object to which the message is sent. Should we modify them to let self be explicitly bound?

-----

5 points by raymyers 6635 days ago | link

Most OO languages don't just "implicitly bind" self; self (or this) is usually a reserved word. A conflict with another variable is made impossible because you can't say "int this = 4" in Java or C++. As pointed out, Python already makes the binding explicit.

Further, let us imagine for a moment that lambda closures and class instances are ... different things.

-----

4 points by cooldude127 6635 days ago | link

not all of them. python, for example, does it explicitly. self is a convention, but you can call it anything you want.

and arc shouldn't do something just because other languages do it. it should do things based on whether they are the best way to do it. and i personally think it's a bad idea to introduce those kind of automatic symbol bindings into constructs which are so fundamental to the language, like fn and if.

-----

2 points by vrk 6635 days ago | link

Pardon the tangent, but in Perl 5 what you call the instance of the class is up to you. Conventionally it's $self, and the constructor is often new(), but these can be whatever you want. Unless you use a special CPAN module that does the work for you, the common idiom in declaring methods is

  sub method {
    my $self = shift;
    ...
  }
You could name it $myself, $this, or even $the_object if you wanted.

-----

3 points by cooldude127 6635 days ago | link | parent | on: Score one for Arc

this is cl code, not arc. that's the joke: he was using an arc style let in common lisp code.

-----

3 points by kennytilton 6635 days ago | link

Right, and the "score one" headline is about my concern that Arc abbreviations might not become second nature. My Arccells code uses a lot of it, but most times I had to go back and edit a (foo bar) into foo.bar cuz the (foo bar) just rolled off my fingers. Of course Arc and I are new to each other so it is too soon to tell, but it feels like my fingers now need a lookahead ability they may not be able to grow. I am especially suspect of the piping : ever catching on.

In this case, I guess the one variable LET syntax of Arc caught on pretty damn fast. :)

-----

2 points by bogomipz 6635 days ago | link

I'm sure you will remember to use foo:bar when the alternative is (fn args (foo (apply bar args)))

Using : only in the most important places might be a good thing. I.e not overuse it for (foo (bar x)) -> (foo:bar x) where it trades readability for 2 characters.

-----

1 point by cooldude127 6635 days ago | link | parent | on: Score one for Arc

why doesn't that work, it's all parentheses? :D

-----

3 points by cooldude127 6635 days ago | link | parent | on: Implicit progn

i would have to disagree about how common the single variable thing is. at least in my own code, i have many more withs than i have let's with multiple statements. but then, i try to do functional programming whenever i can.

and also, arc is at least a little geared toward functional style. in my other comment i brought up that one of the things pg liked about his if version is that the explicit 'do' makes non-functional code more obvious.

-----

1 point by kennytilton 6635 days ago | link

But the more functional the programmer the less likely they are to need temporary variables, so the count 1 should be more frequent! <g> In my CL experience it comes up often enough that I have a policy where the let will be at the toplevel in a function: I use &aux (to repeat, a CL hack):

  (def my-fun (x y z &aux (temp (other-fun x y)))
     ...etc...)
Why? Yes I have a twenty-inch flat panel but I am still an almost obsessive indentation miser, and it just kills me to add a level of parens and indentation just to get one lousy temp variable. :)

-----

3 points by cooldude127 6635 days ago | link | parent | on: Implicit progn

i agree, and pg has stated before that he likes explicit 'do's because they highlight code that isn't functional. this might be considered, i hope.

-----

1 point by cooldude127 6635 days ago | link | parent | on: Does Arc need modules? Maybe not.

what is the point of the eval thing? isn't that what macros are supposed to do by themselves?

-----

2 points by cchooper 6635 days ago | link

You mean like this?

  (mac def-with-prefix (prefix name args . body)
    `(def
        (read (+ (coerce ,prefix 'string)
                 "-"
                 (coerce ',name 'string)))
        ,args
        ,@body))
It doesn't work, because

  (def-with-prefix 'blub 'foo (x) (+ 1 x))
expands to

  (def (read (+ ...blah...blah...)) (x) (+ 1 x))
and def will only take a literal symbol as the first argument. That's also the problem with set I mentioned before.

-----

2 points by shiro 6635 days ago | link

How about

    `(def ,(read (+ (coerce prefix 'string) "-" (coerce name 'string))) ,args ,@body)

-----

1 point by cchooper 6635 days ago | link

Doesn't work I'm afraid:

  (= pre 'blub)

  (your-def-with-prefix pre foo (x) (+ 1 x))
  => #<procedure: pre-foo>

  (my-def-with-prefix pre foo (x) (+ 1 x))
  => #<procedure: blub-foo>
Without being able to take the prefix from the value of a variable, the whole macro is pointless.

-----

1 point by eds 6635 days ago | link

Then why don't you just eval prefix?

  `(def ,(read (+ (coerce (eval prefix) 'string) "-" (coerce name 'string))) ,args ,@body)
It's still much less clunky than expanding the whole def under an eval.

-----

1 point by cchooper 6635 days ago | link

Still has a bug:

  (let pre2 'blub (your-def-with-prefix pre2 foo (x) (+ 1 x)))
  => Error: "reference to undefined identifier: _pre2"

-----

2 points by cooldude127 6635 days ago | link

that's because the macro gets expanded (and thus eval is called on pre2) before the let form is evaluated.

-----

1 point by eds 6635 days ago | link

Yeah, I see the problem with that.

cchooper, did you actually ever run your version? I can't make your orginal version work.

  arc> (def-with-prefix pre foo (x) (+ 1 x))
  Error: "reference to undefined identifier: _x"
And looking at the macro expansion, I'm not at all surprised:

  arc> (macex '(def-with-prefix pre foo (x) (+ 1 x)))
  (eval (list (quote def) ; my indentation
              (read (+ (coerce pre (quote string)) "-" (coerce (quote foo) (quote string))))
              (x) (+ 1 x)))
args and body would need to be quoted for this to work properly. And then it admittedly does what it is supposed to, but it becomes even uglier.

  (mac def-with-prefix (prefix name args . body)
    `(eval (list 'def
            (read (+ (coerce ,prefix 'string)
                     "-"
                     (coerce ',name 'string)))
            ',args
            ,@(map [list 'quote _] body))))

-----

1 point by cchooper 6635 days ago | link

Hmmm... it worked last night. I must have made a mistake when I copied it into the comment. Thanks for catching it.

Here's a slightly less clunky version:

  (mac def-with-prefix (prefix name args . body)
    `(eval (join (list 'def 
                  (sym (+ (coerce ,prefix 'string)
                          "-"
                          (coerce ',name 'string)))
                  ',args)
            ',body)))
I also tried doing it with nested quasiquotes but that just looked worse.

-----

1 point by shiro 6635 days ago | link

Ah, I got it.

-----

1 point by cooldude127 6635 days ago | link

yes, like that. there is no reason i can see for a macro to have to call eval except in the MOST EXTREME cases.

-----

2 points by cchooper 6635 days ago | link

Unfortunately, Arc makes this an extreme case. There's just no way to get the exact required behaviour in Arc without using eval.

In Arc:

  arc> (= foo 's)
  s
  arc> (set foo 4)
  4
  arc> foo
  4
  arc> s
  Error: "reference to undefined identifier: _s"
In Common Lisp:

  CL-USER> (setf foo 's)
  S
  CL-USER> (set foo 4)
  4
  CL-USER> foo
  S
  CL-USER> s
  4

-----

1 point by cooldude127 6635 days ago | link | parent | on: On the need for garbage collection

of course, GC is entirely unnecessary if you're stateless, but that is obviously not what arc's server is.

-----

1 point by byronsalty 6635 days ago | link

Why would GC be unnecessary for stateless servers? Something needs to free memory once the response is committed. Either the interpreter, the server, or your webapp. I prefer the interpreter - that's why I'm not using C.

-----


actually, arc does use the same namespace, that is most of the cause of this problem. if they were in different namespaces, there would be no problem with variables shadowing built-in functions. you still have to worry about variable capture, but it's a much less significant problem.

note: i'm not saying i don't like the same namespace thing. it actually shortens a great deal of code, and eliminates CL's stupid ass #' garbage.

-----


this would be the ideal behavior.

-----


that is very cool.

-----

More