Arc Forumnew | comments | leaders | submitlogin
2 points by alimoeeny 5193 days ago | link | parent

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 5193 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 5193 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 5191 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 5193 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 5193 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 5193 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 5193 days ago | link

This is great, thanks!

-----

1 point by alimoeeny 5192 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 5192 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 5192 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.

-----