Arc Forumnew | comments | leaders | submit | greatness's commentslogin
4 points by greatness 6305 days ago | link | parent | on: Should Arc support infix notation?

wow, good catch. Pretty sure it's not on purpose though. That syntax defies everything that dot notation means. Consider it supported for the same reason Arc has UTF-8 at the minute.

-----

0 points by ryantmulligan 6305 days ago | link

maybe..

-----

3 points by greatness 6305 days ago | link | parent | on: "Axioms" that might need to be added

I like the idea of number two, but I'm not sure how useful it would be in arc where the language seldom requires X amount of arguments; for example:

  (< a)
works just fine and wouldn't be curried. So in order to make currying useful, we'd have to re-write a good chunk of arc code to make some of the optional arguments required.

-----

1 point by drcode 6305 days ago | link

Point taken.

However, the core arc library commands, by their nature, are very general and hence have few mandatory parameters. However, most functions for any actual application will be far more specific and hence, I believe, will tend to be loaded with mandatory parameters. This is the use for case which function currying would be very valuable.

-----

1 point by greatness 6308 days ago | link | parent | on: defstruct in Arc

I believe someone already wrote one, somewhere in this forum.

-----

2 points by kennytilton 6308 days ago | link

This is an extremely lite version (the CL defstruct has a kazillion fetaures, it's CL <g>):

http://common-lisp.net/cgi-bin/viewcvs.cgi/kennysarc2/?root=...

Don't be thrown by the .lisp extensions, it is Arc, I just had to fake my IDE into auto-highlighting the parens.

-----

2 points by greatness 6310 days ago | link | parent | on: core language thingies

I'm not sure if I quite understand you, "(A C)" In your Arc code suggests A is a function. Going by your first posted code, you can achieve this in Arc with:

   (aif (> (+ A C) B) (= A it))

-----

2 points by sjs 6310 days ago | link

When that is true it evaluates to t.

  arc> (= a 2 b 5 c 3)
  3
  arc> (aif (> (+ a c) b) (= a it))
  nil
  arc> a
  3
  arc> (aif (>= (+ a c) b) (= a it))
  t
  arc> a
  t

-----

3 points by greatness 6310 days ago | link

good point, I should have thought that one through. Perhaps we should consider changing the return value of ">" so I'm correct? :P

It seems more useful to have the return value be the greater number if it is true, and since all non-nil values are true, it wont break any existing code. For a > b, consider the following:

  (> a b) => a
  (> b a) => nil
We can make a new > procedure which does this:

  (def >? args
     (if (apply > args) (car args) nil))
repl:

  arc> (>? 5 2)
  5
  arc> (>? 2 5)
  nil
  arc> (>? 7 5 2 3)
  nil
Then, using my definition from before:

  (aif (>? (+ a c) b) (= a it))
It shall now work. Now I'm not stupid anymore. :p

-----

1 point by sjs 6310 days ago | link

Makes sense to me. It's a trivial change in ac.scm for < and >. What about (<= 1 2 3) and (>= 3 2 1)? The easiest way to do the same for those two is to return the last value compared, which would be 3 and 1 respectively. That doesn't exactly jibe with < and > though so I hesitate to make such a change. Thoughts?

It seems logical that <= and >= should also return some meaningful value if < and > do. If we come up with something good I'll push it to the anarki repo (git wiki). Although, we could always just ignore <= and >= for now.

-----

1 point by greatness 6306 days ago | link

Why not follow the same idea as < and >:

  (def <=? args 
    (if (apply <= args) (car args)))

-----

1 point by sjs 6305 days ago | link

I should have been clearer. I agree the semantics should be the same, I just didn't see an immediately clean way to add that to the current, recursive <= and >= functions. A thin wrapper would work just fine.

-----

1 point by greatness 6301 days ago | link

Yeah, either that or use a lambda function inside their definitions:

  (def >= args
    (let f (afn (ar) (or no.ar
                       (no:cdr ar)
                       (and (no:< car.ar cadr.ar)
                       (self:cdr ar))))
      (if (f args) car.args)))

-----

1 point by bOR_ 6310 days ago | link

just ment A B and C to be numbers.

Got it.. thanks for introducing me to anaphoric macros :). Now the question is whether writing macros and having several aifs aands awhile aif2s for it is the way to go, or whether it is something that might be core-worthy, in a way that gosub (see post below) suggested.

-----

1 point by greatness 6313 days ago | link | parent | on: Arc Repo

Excellent, could we get some sort of separate forum to talk about this project though to discuss bugs, recent patches, etc.. I noticed you have a module system up now, but I can't get it to work:

  arc> (impas blah spec)
  #3(tagged mac #<procedure>)
  arc> (blah:do2 nil nil nil)
  Error: "reference to undefined identifier: _blah"
And I'm not sure why it doesn't work, but I also have an Idea for a more general impas function:

  (mac impas mods 
    (do (map [apply importmodule _] (pair mods)) 
          nil))
(keep in mind this is entirely theoretical, I couldn't physically test it because the other impas didn't work.)

-----

1 point by randallsquared 6312 days ago | link

The import.arc stuff is a sketch. One of it's many shortcomings is that if you define a function blah and then use it from inside the same module/file, it won't be able to find blah, because it's been silently renamed |modulename blah| .

The problem you're having seems to be different, though.

After looking, I realize that my testing process was masking a bug where I didn't change some symbol dereference. It's fixed now on my machine, but I'm new to git, and not sure what I need to do to make it show up in the repository. I did git push, but that doesn't seem to have made it appear in the commit list.

EDIT: okay, nex3 helpfully explained things to me, so this fix is in the arc-wiki repo now. It still doesn't change use points, though, as mentioned above.

-----

1 point by randallsquared 6312 days ago | link

Replying to myself because it seems as good a place as any...

We could walk the tree of a module and patch up any symbols we find that were referenced in a def or mac, but that's not a clean solution, since it can't find all actual calls (something could be building up names, for example, which we'd never find by walking the tree).

What this means is that any module system built right now, as far as I can tell, will have to require support from those writing the modules, but since renaming modules is implicit in how import.arc works at the moment, there's no way to know what the call should look like, for the module programmer. I can't see any way around this except to change Arc itself to make function and macro definitions respect lexical boundaries, rather than all being bound at the top level. Until that change is made, all we can do is fake a module system.

-----

1 point by randallsquared 6312 days ago | link

My own thought was that we'd have an

    (impfrom modulename name1 name2 ...) 
such that only those names would be imported, like Python's

    from modulename import name1
and that then impas would be extended to take given names as well, like

    (impas newname modulename name1 name2 ...)
However, I don't feel strongly about it either way.

-----

1 point by nex3 6312 days ago | link

I think this forum is as good as any for now.

-----


I was thinking more like this:

  (def curry (f . args)
    (fn args2 (apply f (join args args2))))
which is pretty much the same thing except without it being a macro. I've found that with the [] syntax, currying doesn't really improve code brevity.

-----

2 points by greatness 6313 days ago | link | parent | on: Multi-var function literal shorthand

I was thinking that _ would be merely _0, ie _1 would be the second argument. But at this point that's not really the question, the question is how will the interpreter know how many arguments the function takes?

Maybe something like:

  [[[+ _ _1 _2]]]
Could be shorthand for:

  (fn (_ _1 _2) (+ _ _1 _2))
But, then, what if you want to use square bracket notation inside of that? For example, what if you want to create a two paramater function that creates a one paramater function?

  (fn (x y) [+ x y _])
would be impossible. Unless you use currying or something on these special ones. Incidentally, a curry function:

  (def curry (f . args)
    (fn args2 (apply f (join args args2))))
Then you could simply do:

  (curry + var1 var2)
Assuming you already have the variables. For smarter currying it'll need to be done by the interpreter.

-----

1 point by greatness 6313 days ago | link | parent | on: Updated range with step

A little prettier perhaps, though follows the same idea:

  (def range (st en (o step 1))
    (if (is step 0) (= step 1) (zap abs step))
    (let (stp-fn test) (if (> st en) `(,- ,<) `(,+ ,>))
       ((afn (i accum)
          (if (test i en) (rev accum)
                          (self (stp-fn i step) (push i accum))))
        st nil)))
If what order you want the range doesn't matter, you can remove the (rev accum) and replace it with accum. Example output:

  arc> (range 0 -5)
  (0 -1 -2 -3 -4 -5)
  arc> (range 5 5)
  (5)
  arc> (range 0 5)
  (0 1 2 3 4 5)
  arc> (range 0 10 2)
  (0 2 4 6 8 10)
  arc> (range 10 0 2)
  (10 8 6 4 2 0)
EDIT: added some error-checking, changing a step from 0 to 1 probably isn't the right thing to do, but I didn't feel like figuring out how to throw an error.

-----

1 point by greatness 6313 days ago | link

Turns out consing up the list is faster, though without the rev function it is very close:

  (def range (st en (o step 1))
    (if (is step 0) (= step 1) (zap abs step))
      (let (stp-fn test) (if (> st en) `(,- ,<) `(,+ ,>))
        ((afn (i)
           (if (test i en) nil
                           (cons i (self (stp-fn i step)))))
         st)))
though I don't know why.

-----

1 point by joseph 6312 days ago | link

How about a default start of 0?

  (def range (default (o end) (o step 1))
    (with (st (if end default 0)
           en (if end end default))
      (if (is step 0) (= step 1) (zap abs step))
      (let (stp-fn test) (if (> st en) `(,- ,<) `(,+ ,>))
         ((afn (i accum)
            (if (test i en) (rev accum)
                            (self (stp-fn i step) (push i accum))))
          st nil))))

-----

1 point by greatness 6314 days ago | link | parent | on: Clarification about Character Sets

I agree, this is probably the best solution.

-----

3 points by greatness 6314 days ago | link | parent | on: List of Arc Functions and Macros

Different styles of organization would be nice:

* Category (input/output, list functions, etc.)

* Function or Macro (Split them up and alphabetize them)

* Alphabetical (all in one giant alphabetical list.)

* By file (arc.arc, app.arc, etc.)

You're already doing a combination of two of these, but you should give them as separate options; or perhaps keep what you have and just add all these options. Shouldn't be that hard if you keep all the definitions in a database, with the information required to do this.

-----

More