Arc Forumnew | comments | leaders | submit | alimoeeny's commentslogin

I didn't know about rlwrap! it's relief! At least now I can begin to work.

-----

1 point by evanrmurphy 5157 days ago | link

I'm glad it's working out for you!

-----

2 points by alimoeeny 5160 days ago | link | parent | on: How do you use arc in real world?

Hi There,

Thanks a lot, for taking care of the anarchy I caused in the Anarki!

From now on I'll commit to my fork and if there was any thing of general interest you can pull it to master later.

I noticed you mentioned "it would be better if matrix was its own type" I agree with that. Is there any way to communicate this with pg (or anybody else who has a say on such basic matters) and see if matrix could be implemented as its own type?

As you know I am an absolute newbie in arc/lisp but I find it quite refreshing to solve (or re-solve) problems the arc/lisp way.

Cheers, Ali

-----

3 points by garply 5160 days ago | link

Actually, do you mind pushing to Anarki instead (unless you have some really risky code that could break a lot of stuff)? Totally up to you, but I'm of the opinion that if we're all hacking in the same repo, our community will be stronger.

A growing set of files in lib/ doesn't really hurt anyone, and if someone really hates your or my code, they're free to rewrite it, or just not load that library.

It's pretty obvious that people like aw, shader, and fallintothis (off the top of my head) are much better scheme hackers than I am, but I don't think I've stepped on their toes too much, and if I think I'm going to, I'll ask the forum about pushing something.

Regarding implementing matrix and vectors as their own types, if you can do it and have the time to do so, you don't need to wait for PG's permission. For my needs at least, Anarki is the more useful tool and PG, while he is the original creator, is just a periodic contributor like the rest of us (although he doesn't push to github - one of us ends up merging his stuff).

Oh, and your variable capitalization style (is duck typing the name? I can't remember) is a little out sync with the community style. Just a heads up :)

-----

2 points by fallintothis 5160 days ago | link

is duck typing the name? I can't remember

Hehehe. Well, it has to be something with an animal! :) I think you mean camelCase.

</useless contribution>

-----

2 points by alimoeeny 5160 days ago | link

Great,

I'll push to Anarki, I like the idea of sharing the same code pool when people are free to load a library or not.

My free time is a random variable with large variance but this seems to me a small but lively community which boosts the motivation.

Thanks for the tips, Ali

-----

2 points by akkartik 5159 days ago | link

Since we're talking about vectors and matrices - one of the things I've been wanting to do is define + as a generic (see iso). There's been some discussion about the pros and cons of overloading + for strings (http://arclanguage.org/item?id=12347) but for mathematical entities it should be fine.

A more intense project is to come up with some nice way to extend coerce without needing to modify ac.scm each time. Was there ever a way to do this in anarki, does anyone know? Maybe in the arc2 branches?

-----

2 points by garply 5159 days ago | link

aw wrote a mac named, oddly enough, "extend" which I put into extend.arc in the anarki libs.

From: http://awwx.ws/extend0

  For example, here is an extension to + to combine tables:
  
  (extend + args (isa (car args) 'table)
    (listtab (apply + (rev:map tablist args))))
  arc> (+ (obj a 1) (obj b 2) (obj a 3 c 4))
  #hash((b . 2) (c . 4) (a . 1))
I know you've been working a bit with generics, which I'm not familiar with. I really haven't looked into your code (except to note that you have something in arc.arc which throws me redefinition messages whenever I start up arc), do you have an easy way to create a vector and matrix type? Seems like aw's "extend" and a "vector" method which allowed me to create something that returned type 'vector would be sufficient to get the ball rolling.

-----

2 points by akkartik 5157 days ago | link

rocketnia had a nice comparison of extend with defgeneric in the original thread: http://arclanguage.org/item?id=11779. aw chimed in as well: "If there's a facility that does what you need, use it, but if there isn't, use 'extend ^_^" :)

(Thanks for the pointer to coerce, rocketnia)

My experience since then has been that the efficiency of a hash-table lookup is irrelevant. But I really like the conciseness and readability of being able to say:

  (defmethod foo(arg1 arg2) type-of-arg1
    ...)
---

"you have something in arc.arc which throws me redefinition messages whenever I start up arc"

Ack, guilty as charged; I should fix that..

(update: fixed http://github.com/nex3/arc/commit/f8717f9dc3a13e4a6222120533...)

-----

2 points by rocketnia 5159 days ago | link

If you're just concerned about having the type 'vector, you can use Arc's (annotate type representation) function to give a value a wrapper with a custom type, and you can use the (rep wrapper) function to unwrap it.

If you're actually talking about vectors in the Scheme sense (arrays), there'll be a few more hoops to jump through, but that's not really what you mean, right?

-----

2 points by garply 5159 days ago | link

Thanks! I pushed a little bit of progress to lib/statistics.arc. I'd also like my vectors to function like lists.

  (= a (vec 1 2 3))
  type.a => 'vector
  (a 0) => 1
The list index referencing w/o first calling rep seems like it would require hacking ac.scm, right?

-----

2 points by rocketnia 5159 days ago | link

In Anarki, the hacking has already been done. ^_^

  (defcall vector (vec i)
    rep.vec.i)
The original 'defcall post is way back here: http://arclanguage.org/item?id=3743

Since then, it's been redefined in terms of [coerce _ 'fn] and an extensible implementation of 'coerce. http://arclanguage.org/item?id=9828 (Here you go, akkartik!)

Rainbow also supports 'defcall, but in the more direct way rather than through extensible coercion.

-----

1 point by garply 5159 days ago | link

This is great, thanks!

-----

1 point by alimoeeny 5158 days ago | link

Sorry guys, would somebody summarize this discussion on vectors and matrices? I mean after all is there any merit in defining a generic matrix type for everybody to use or people better define their own for their specific job. I am still trying to read the documentation, this is all new for me.

-----

2 points by rocketnia 5158 days ago | link

Well, what is there to summarize, hmm...

Looks like garply is putting together a library which deals with matrices and vectors and wants to be able to say (isa x 'vector). The 'annotate and 'rep functions make that happen. Anarki also defines 'defcall so that new types like these can be given special behavior when used as functions.

In one sense, garply's defining a matrix type for every Anarki user to use. In another sense, it's only a matrix type specific to the purposes of that library. But in any case, if this type doesn't look good to someone, they can just follow the same process to define their own type and forget this one exists at all. :-p

Realistically, I think efficiency is one of the things at the top of people's minds when they're trying to do computation with matrices, and with all due respect to garply, I doubt the project is going to get to the cutting edge of matrix efficiency anytime soon. >.> So I actually do expect someone to decide to define another matrix type later on. Nevertheless, garply's contributions could certainly help that person along. ^_^

-----

1 point by garply 5158 days ago | link

You're absolutely correct. I would go so far as to say that Arc itself is too slow to do any serious matrix computations (maybe if you made this just an interface to some Racket matrix libs you could work around it). I'm really not going to bother thinking about efficiency much at all. What I have done before in Arc is prototyped some algorithms on very small test sets. Once I got those working and figured out what I actually wanted, I rewrote everything in C++ or C, with a very close eye to efficiency.

I used to use this strategy all the time with an R / C combination, but I greatly prefer writing in Arc. Lush is kind of the best of both worlds, except the last time I pulled the bleeding edge version there appeared to be some crippling, hard-to-find bugs. Plus it's nice to just be able to build quick prototypes when you're already in Arc.

-----

1 point by alimoeeny 5161 days ago | link | parent | on: How do you use arc in real world?

I mean 1) if I want to run a web app I don't want my server to depend on an interactive console, I want to run it (them) in the back and stop and start them and ... 2) if I want to run something on a host or a cluster (neither usually have the interactive console, so a binary could help there In other words, can you give me some use cases that I can understand how you develop and deploy arc apps?

By the way the documentation link in arcfn.com is what I was missing, thanks.

-----

2 points by aw 5161 days ago | link

I like using the "screen" program (available on most servers, try typing "man screen"), which lets me pop in and see any error messages.

For an automated startup, you might try something like this shell script (after modifying libs.arc to load your code):

  #!/bin/sh
  cd /location/of/arc/directory
  nohup mzscheme -f as.scm >log 2>&1 &
a caveat here is that "nohup" redirects stdin to /dev/null which in turn will cause Arc to go into an infinite loop if it gets to its REPL, a trick is to have the last thing called in libs.arc be "(serve)" (or "(asv)" etc.), which doesn't return and thus Arc won't get to the REPL prompt.

-----

2 points by alimoeeny 5161 days ago | link

Thanks, I use screen all the time, still I fill there is a lot fundamental differences between ways of arc and ways of "bulb" (python for me) that I need to learn. By the way the idea behind Anarki is that people come and fork and if they did something worthwhile it could be merged back, right?

-----

3 points by shader 5161 days ago | link

Yes, the main purpose of Anarki is as a place for people to share the work they've done on/for arc. Since arc itself is easily modified, a lot of the code on Anarki actually changes the language. There is also a fair amount of library developed there as well, though since most important library functions can be lifted from Racket that's not so much of an issue.

However, beyond simple bug fixes pg hasn't ever discussed much about changing the language itself with the community. As far as I know, none of even the truly good, simplifying and useful features of Anarki are planned to be lifted to arc.

-----


any help with this one: xy = 0; for ( i ...) { xy += (x(i) - mean(x)) * (y(i)- mean(y)) } .

-----

1 point by alimoeeny 5162 days ago | link

Any ideas why this doesn't work: (def s (x y) ( (= mx (avg x)) (= my (avg y)) (reduce + (map * (map [- _ mx] x) (map [- _ my] y)))))

-----

4 points by fallintothis 5162 days ago | link

For one, you have an extra set of parentheses around the body of the function. Parenthetical expressions like

  (expr1 expr2 expr3 ...)
by default will evaluate expr1 and try to call it with the arguments expr2, expr3, .... E.g.,

  arc> (+ 1 2 3)
  6
This sort of rule applies recursively, so

  ((if (> 1 2) - +) 1 2 3)
first evaluates

  (if (> 1 2) - +)
which returns the function + (since (> 1 2) is false), meaning the original evaluates to

  (+ 1 2 3)
There are a few places where parenthetical expressions don't evaluate this way, but they're usually pretty obvious -- like the argument list in a def. For more details, the tutorial is a decent place to start learning about Arc & Lisp programming: http://ycombinator.com/arc/tut.txt.

To fix your code immediately, you'd just need to get rid of the extra parens. Expressions in the body of a function evaluate one after the other, returning the value of the last expression, so given

  (def f (x)
    (+ x 1)
    (+ x 2))
a call to f will calculate (+ x 1) and (+ x 2), returning the latter.

But you should (generally) only use = for global variables. For local ones, you'll want with or let.

  arc> (let x 1 (+ x 1))
  2
  arc> (with (x 1 y 2) (+ x y))
  3
So, the function

  (def s (x y)
    (with (mx (avg x) my (avg y))
      (reduce + (map *
                     (map [- _ mx] x)
                     (map [- _ my] y)))))
should do what you want. You could still perform some "map fusion". Roughly speaking,

  (map f (map g xs))
is equivalent to

  (map [f (g _)] xs)
and you save on doing multiple passes through your lists. Thus,

  (def s (xs ys)
    (with (mx (avg xs) my (avg ys))
      (reduce + (map (fn (x y) (* (- x mx) (- y my)))
                     xs
                     ys))))
is arguably cleaner, though the two-argument function does clutter stuff up a bit.

You can also write the same "destructive" style of code in Arc, though it's normally frowned upon.

  (def s (x y)
    (let xy 0
      (for i 0 (- (min (len x) (len y)) 1)
        (++ xy (* (- (x i) (avg x))
                  (- (y i) (avg y)))))
      xy))
Finally, to format code,

  put a blank line, then at least two spaces before the line of code
  (similarly for subsequent lines)
See http://arclanguage.org/formatdoc for details.

-----

2 points by alimoeeny 5162 days ago | link

Thanks a lot, that was great help, I never felt so excited about coding in a new language since Commodore 64's BASIC!

-----


That was quite helpful.

-----