Arc Forumnew | comments | leaders | submit | bOR_'s commentslogin
1 point by bOR_ 6277 days ago | link | parent | on: Improve this function 2 =)

Good call. Not necessarily want to use showpos.. its main advantage right now is that it nicely returns nil when I try to read any out-of-bound position.

I guess without showpos I could grab the appropriate rows from world and discard the first X and last Y positions.

-----

1 point by bOR_ 6277 days ago | link

There we go. That looks like a solution I was looking for :). and cut nicely takes care of out-of-bounds too.

  (map (fn (_) (cut _ (- row 1) (+ col 2))) (cut world (- row 1) (+ col 2)))

-----

1 point by bOR_ 6276 days ago | link

ugh. just don't mind the nonsensical placing of row and col, it should be row row, col col

-----

1 point by almkglor 6276 days ago | link

  (map [cut _ (- row r) (+ row r)] (cut world (- col r) (+ col r)))

-----

1 point by bOR_ 6276 days ago | link

From here on I adapted the function to the one I really needed (do something if one of the 8 neighbours of posx, posy is X). Because of that requirement it seemed easier to just gather the row - 1 and row + 1 and the row, col - 1 and row, col + 1, and join those in a list. This is what it ended up as:

   (if (find X (flat:map [join (errsafe (world _))] (list (- row 1) (+ row 1) (- col 1) (+ col 1))))
    ; do stuff
    )
Thanks for the help!

-----

1 point by almkglor 6276 days ago | link

  (flat:map [join (errsafe (world _))] (list (- row 1) (+ row 1) (- col 1) (+ col 1)))
This bit doesn't seem correct... world is addressed by row right? Why are you also addressing by column?

-----

1 point by bOR_ 6276 days ago | link

yeah. realized this night (dreaming is a wonderful thing) that I'm now making a mess out of it, rather than just looking at neighbours. bug! ;).

But as far as I'm concerned, I've had enough help already. Should be able to take it from here.

-----

2 points by bOR_ 6277 days ago | link | parent | on: Arc's web server in Lua

If rails is to be considered the killer library of ruby, it took five years for it to show up.. so we have some time left ;)

-----

2 points by stefano 6276 days ago | link

That's true. Programming languages take years to evolve, not months. Moreover, Arc is in the language design phase. As of today, the syntax and the semantics of the language are more important than libraries. For example, I'd like to see something like Kenny Tilton's cells (http://github.com/stefano/cells-doc/) nicely integrated within the core language.

-----

2 points by lojic 6276 days ago | link

Is it in the language design phase? Does anyone know if this is in fact true, and if so, what is currently being designed? The impression I have is that it just sort of stopped.

-----

2 points by shader 6276 days ago | link

I would suppose that since a) this language is not used in anything "important" yet, and b) it's open source; yes, it can be in the design phase. I should think that the design phase persists until, for some reason, the language becomes "formalized", or until it is impossible to change anything major without ruining things for a lot of people. At that point you can still "design" the language, but since it has a generally understood "style" and so forth, it won't be able to change too much unless you make a whole new language.

What do you want to be designed? One of the major problems about "designing" a new lisp is that, since anyone can "do it" in their spare time, they don't see the point. Maybe they're right. ^^

Sorry for all of the quotes; it looks kind of funny, I'm sure.

-----

1 point by bOR_ 6280 days ago | link | parent | on: Is, lists, and strings

Ah.. but here PG is wondering into the opposite direction of what eekee is, if I understand correctly.. PG seems to be favoring the following distinction:

is .. checks if a is the same thing as b (like pointers referring to the same address in memory).

iso .. checks if the content at whatever a is pointing at is the same as whatever b is pointing at.

which is now violated by strings. I am not sure how numbers fit into this. In general I would favor the more commonly used 'has the same content as' to be is, and 'refers to the same entity' to be iso for brevity reasons.

-----

2 points by oconnor0 6274 days ago | link

But isn't iso short for isomorphic which, as I understand it, is the same as "these two things are equivalent" - which maps much more closely to "has the same content as," not "refers to the same entity"?

-----


Which is a bit hard not to know.. I mean, in order to install Arc you have to install scheme.. and the install link right next to the tutorial link makes that clear.

Oh well.

-----

1 point by bOR_ 6282 days ago | link | parent | on: Ask The Community: Lexical Scoping

Sounds intriguing ;), but I miss the implications of your observation. Can something nifty be done with this?

-----

1 point by almkglor 6282 days ago | link

Yes: a code-walker interpreter with dynamic lookup can implement lexical scope, provided you don't pass functions around (on the interpreted-language side).

If you do pass functions around though, you need to keep separate slightly-different versions of the environment variable, and attach those to the functions you pass around on the interpreted-language side.

-----

3 points by bOR_ 6285 days ago | link | parent | on: Primitives and library functions

is this what you need?

http://arcfn.com/foundation-doc.html

-----

2 points by lboard 6285 days ago | link

primitives in the sense, i mean functions like quote, atom, eq, cons, car, cdr, cond, eval,

There should be a limited set of funcitons like that. On top which we write other stuffs.

Where is the dividing line, in arc.

-----

3 points by drcode 6285 days ago | link

Arc is desinged as a practical language, and as such it is not built on any pure primitives. PG had, at one point, taken such an approach, but abandoned it because of poor performance.

It calls many mzscheme functions to run, most of them not primitive. Primitives, as far as they exist, are defined in ac.scm. They are not simple, however- Instead, the emphasis is on keeping the language implementation simple and reasonably efficient.

-----

1 point by almkglor 6283 days ago | link

> Arc is desinged as a practical language, and as such it is not built on any pure primitives. PG had, at one point, taken such an approach, but abandoned it because of poor performance.

Personally I'm retaking this approach, and doing some trickery on the scheme side to improve performance. So far what I've been doing is only slightly slower than Anarki (within sampling variation, although the average times are slightly higher).

-----

6 points by bOR_ 6288 days ago | link | parent | on: Javascript / arc / google chrome / v8

also noticed that the difference isn't that large as the racing car seemed to suggest. Chrome's javascript has about the same performance as Opera's right now. We'll see how it develops.

Hah. someome made ruby run on v8 and made a small benchmark of it. Interesting:

http://macournoyer.wordpress.com/2008/09/02/ruby-on-v8/

-----

2 points by bOR_ 6295 days ago | link | parent | on: A proposition for regular expressions in Arc

I am not sure what the consequences are for possible implementations, but preferrably, I would want to be able to use regexps in (find or (keep, or (findsubseq just as easily as I would now use strings or functions

  (keep odd (list 1 2 3 4))
  (keep (reg /nan/) (list "banana" "bonobo" "bandanga"))
  (findsubseq (reg /\d+:\d+/) "The current time is 10:00 am")
When looking at http://arcfn.com/doc/string.html , there is an aweful lot of restrictions on when we can use variables, or functions as arguments, so maybe a lot of the string operations in there become obsolete if there is a regexp engine in arc.

-----

2 points by bOR_ 6309 days ago | link | parent | on: Improve this function?

Thanks for the improvements!

@rincewind - nice one. (apply + is indeed one of the most obvious improvements I should familiarize myself. Familiar with it in ruby (inject), but in combination with recursions, I fell back to the simpler (with. acons is a good pointer as well for me.

@drcode - solution: "try to take the average of each element in a list. If that doesn't work, return the element". Didn't know about avg, which is an obvious improvement. errsafe and or are whole new operators to me, which are going to be interesting to try and learn to use. Nice!.

@skenney26 - might still be a bit too difficult for me.. the function rec takes 3 arguments (an operator, a base whose purpose I'm not sure of, and the list). rec creates an internal function called 'r'. If xs is an atom (i.e., not a list) then 'r' returns (base xs), otherwise it maps, calling r recursively.

Ok. think I get what base is for :).. it allows you to modify the numbers before you subject them to f. Nice!

Thanks all of you!

-----

1 point by skenney26 6309 days ago | link

Actually, I'm with you on rec. Even after writing it my head was struggling to fully understand it. Complex recursion is tough to grasp; i wish there was a way of visualizing recursive calls that was similar to expanding a macro. Does anyone know if there's a way of doing that?

-----


I'll put in a bit more detail., hopefully enough. It might be that I indeed need a macro, but it could also be some oversight in me.

Given the function

  (def dot (g x y)
     (* (g 0) x) + (* (g 1) y))
(which evidently expects g to be a list, and x and y to be numbers), I get this error message when supplying it with variables.

dot((list 0 -1 1) 0.3 0.3) #<procedure: dot> arc> Error: "list-ref: expects type <non-negative exact integer> as 2nd argument, given: 0.3; other arguments were: (0 -1 1)"

-----

3 points by rntz 6312 days ago | link

You can't use "foo(bar)" to call foo on bar in arc, you have to say "(foo bar)". Interpreting "dot((list 0 -1 1) 0.3 0.3)", Arc first evaluates 'dot (doing nothing) and then evaluates ((list 0 -1 1) 0.3 0.3), which calls the newly created list '(0 -1 1) on the two arguments 0.3 and 0.3, which in turn causes an error because it's trying to get the 0.3rd element from the list, which makes no sense. (Also it's been given two arguments when it expects only one.) This is a case of Arc not having very informative error messages.

Also, I think there's an error in the 'dot function, as you use a '+ where it will do nothing. Arc has no infix math, so what you want is something like this:

    (def dot (g x y)
      (+ (* (g 0) x) (* (g 1) y)))
    
    (dot (list 0 -1 1) 0.3 0.3)

-----

1 point by bOR_ 6312 days ago | link

arg. that's a silly error of mine. I translated the program from ruby, and that one must have slipped.

-----

More