Arc Forumnew | comments | leaders | submitlogin
1 point by globalrev 6063 days ago | link | parent

without thinking i see i used a input witht he same name as the function.

this doesnt seem to cause a problem though. so it is ok or can be a problem?



1 point by wfarr 6063 days ago | link

I believe so.

Because the 'def macro uses '= to define functions, variables and functions are occupying the same namespace (sort of).

For example:

  (def foo () (prn "bar"))
is expanded to:

  (= foo (fn () (prn "bar")))
For example:

  > (def foo () (prn "bar"))
  #<procedure: foo>
  > (= foo "foo")
  "foo"
  > (foo)
  Error: "procedure ...r/src/arc/ac.scm:1224:11: expects 2 arguments, given 1: \"foo\""
Make sense?

Though, that may not affect your usage here since power is just an argument and not a variable itself.

-----

1 point by cchooper 6063 days ago | link

In this case it's not causing a problem. You're allowed to give parameters whatever name you want, but if you name the parameter after the function then you can't call the function from within itself because the name will now refer to the argument.

So if you don't need to call the function recursively, there's no harm. It's just a bit confusing.

-----