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

Well, I do not totally agree with you there. I have programmed in Arc both for fun and work, and have also coded in Scheme a little, and I really find the . and ! syntax is really a good thing for structure access, mainly when you have nested structures. You know, when you have 3 or 4 opening parentheses at the same time. Too sad you can't fully use it in these situations.

But it's not a problem of fear of parentheses ; actually I couldn't find other cases where . and ! could be used without feeling a bit ugly (i.e. in calling functions or macros). Yes, parentheses & s-exprs are great, but I don't believe they should be the only syntax for accessing structures.

Don't worry anyway, I don't think Paul would integrate suggestions he considers weak, even if many of us asked it.

-----

1 point by sacado 6493 days ago | link | parent | on: Community wiki

This is also an occasion to :

   - prove (once more) Arc can be used in real apps
   - experiment a little more with the language and see what's good / what's not good yet with it

-----

1 point by byronsalty 6493 days ago | link

One thing that it's not good at (as far as I could tell) but is generally useful for a wiki is file uploads through web. I'm planning to add this myself but it's about 3rd or 4th on my list so I won't be upset if someone else beats me to it. hint hint.

-----

5 points by sacado 6494 days ago | link | parent | on: Community wiki

Very good idea. I think it would be better if it was done by pg on this site. Spreading Arc stuff all around the web is not the best way to have a united community. And the problem would remain the same : how could someone coming in a few weeks know where that wiki is ?

What do you think of it pg ?

-----

6 points by byronsalty 6494 days ago | link

Good point. Arclanguage.com has to link to the wiki at the same level as the tutorial and forum.

I think this would be sufficient.

-----


I'd like a.b.c to be ((a b) c) too !

-----

2 points by drcode 6494 days ago | link

I agree- using dots/exclamations in multiparameter functions is definitely pretty scuzzy, so it makes sense to use this semantic space for something else, too...

The reader (I would argue) should always make the assumption that the dot/excl implies single-parameter functions. This would be particularly nice in nested tables... Imagine we had a table of tables of city populations:

countries!usa!atlanta --> "5 million"

-----

2 points by cooldude127 6494 days ago | link

this would be the ideal behavior.

-----


You can use one hash table per type of shape (that would be called a class in many other languages :). For example, a hash called sphere and one called plane. Each of these hashes would have an entry whose key is the generic name of the function (intersect, etc.) and whose value would be the implementation of the function for that type.

Thus :

  (= sphere (table))
  (= plane (table))

  (= (sphere 'intersect) (fn (sphere . rest) ...)
  (= (sphere 'normal) (fn (sphere . rest) ...)
  (= (plane '...
Then, you could put all these hashes in another englobing hash, whose keys would be the names of the types and the values their associated table :

  (= classes (table))
  (= (classes 'sphere) sphere)
  (= (classes 'plane) plane)
Finally, if x is your object and (car x) gives you its type, you can call its intersect function this way : (withs (type (car x) class (classes type) function (class 'intersect)) (function x))

If you have parameters, they must be added after x in the last line. Basically, that's it. But there are many other possibilities if you don't like this one for any reason. And anyway, maybe someone else will give you a better one.

Edit : changed circle with sphere

-----

6 points by kennytilton 6494 days ago | link

And once that is working and it starts to get irritating, you are ready for mac, the anti-irritant. create a file called clos.arc and:

  (mac defmethod (gf-name ((self type)) . body)
     (w/uniq (class)
       `(let ,class (ensure-class ',type)
           (= (,class ',gf-name)
              (fn (self) ,@body)))))
...or something in that general ballpark, I just banged that in over a neat Johnny Walker.

-----

3 points by kennytilton 6493 days ago | link

I would like to emphasize the bit "once that is working"... it can be a bit much to get the whole mechanism working at the same time as developing the macro. So get the flow going from a text file being read in to the correct function being called for that shape and maybe do a few shapes until you are sure the beast is about right, then do the macrology. Especially if a macro is in a separate file (as it should be) and you are not reloading the whole shebang each time you run, you'll go nuts running old code even after changing the macro if you just reload the macro-defining file. Add to that the fact that the mechanism itself will be a moving target... well, I like to divide and conquer these deals.

-----

2 points by comatose_kid 6493 days ago | link

Thanks Kenny and Sacado. I'll try to digest your code/ideas later this evening.

-----

3 points by drcode 6494 days ago | link

at 6AM? For shame, Kenny :)

-----

2 points by kennytilton 6493 days ago | link

You don't like a little nightcap before turning in?

-----

1 point by sjs 6493 days ago | link

As long as he wasn't just waking up... ;-)

-----

2 points by greatness 6493 days ago | link

instead of using (car x) to store the object type is there a way to use annotate to do it? I'm kind of confused on how that works.

-----

1 point by sacado 6493 days ago | link

Yes annotate is the arcish way to do so I think. Just do (= x (annotate x 'sphere)) and after that (type x) would give you what you want.

-----

1 point by sacado 6495 days ago | link | parent | on: Modules : a proposition

What about something like what you are proposing, but where you have to explicitly state when you use the module namespace, since we obviously can't overwrite = without sad effects ?

For example, let's take the $ symbol (another ugly one :) to mean "the current module". The above could be written :

  (module foo (export a bar)
      (= $!a 'in-top)
      (def $!foo (x) (+ x 1))
      (def $!bar (x) (+ x 1))
      (pr a))
    (prn foo!a)
    (foo!bar 0)
    (= bar foo!bar) ; an import.
    (= a2 foo!a)    ; a qualified import.
Advantages : - very simple - written in pure Arc (thus candidate to the core language)

Here's a macro implementing part of that behavior : (= $ nil) (= $path* '()) ; Current module hierarchy

  (mac module (name . body)
        (w/uniq old-$
                `(with (,old-$ $)
                        (= $ (table))
                        (push $ $path*)
                        ,@body
                        (pop $path*)
                        (if $path*
                                (= (,old-$ ',name) $) ; Put it in the parent
                                (= ,name $))          ; Put it in global namespace
                        (= $ ,old-$))))
It supports imbricated modules. To import a module, or do a qualified import, the classical table manipulation functions work.

  (module foo
    (module bar
      (= $!baz 'arc)))

  arc> foo
  #hash((bar . #hash((baz . arc))))
  arc> (= bar foo!bar)
  #hash((baz . arc))
  arc> bar!baz
  arc

-----

2 points by raymyers 6494 days ago | link

It sounds like several of us are working on different module ideas. How about we start throwing our prototypes in a `lib/module' directory on the git?

-----

1 point by almkglor 6494 days ago | link

Done, hacking off yours since it was already there ^^

-----

1 point by sacado 6495 days ago | link | parent | on: Modules : a proposition

  arc> (macex 'foo:bar)
  foo:bar
Too bad :(

-----

1 point by sacado 6495 days ago | link | parent | on: Modules : a proposition

There's a problem with using = and def. I tried it, but many parts of the core and libraries assume a unique namespace. As commands can have many side-effects, everything breaks easily.

But the idea of using tables is excellent.

-----

1 point by sacado 6495 days ago | link

Anyway, we must be able to access the global namespace too. If you overwrite = and def, you can't. Or you have to define g= and gdef :)

-----

4 points by almkglor 6495 days ago | link

Here's a different idea. Suppose that instead we build a basic modulesystem which transforms:

  (modules-base
     ;name of module.
     foo
     ;set of functions in this module
     (bar)
     ;set of module variables
     (nitz)
     ;set of functions from other modules
     ((module2 hmm niawniaw))
     (def bar (x) (hmm) (niawniaw) (do1 nitz (= nitz x))))
to:

  (= foo
     (with
        (bar nil nitz nil hmm module2!hmm niawniaw module2!niawniaw)
       (= bar (fn (x) (hmm) (niawniaw) (do1 nitz (= nitz x))))
       (fill-table (table) 'bar bar)))
Then we create another macro which simply scans through the code for (def ...) forms and transforms the following code:

   (module foo
     (use module2)
     (module-vars nitz)
     (def bar (x) (do1 nitz (= nitz x))))
to:

  (modules-base
     foo
     (bar)
     (nitz)
     ;gotten by taking (keys module2)
     ((module2 hmm niawniaw))
     (def bar (x) (do1 nitz (= nitz x))))
Weaknesses: (1) we can't make module-variables accessible outside. If we had access to environments, though, we could.

(2) macros are impossible as yet, whether shared or not. Possibly, we need macrolet, and adding some mechanism to store macros separately from the module table - possibly in a table-of-tables module-macros.

Implementation: simple scanning would be nice. However, modules-basic would be better implemented by a 'macrolet form.

Conclusion: We need macrolet.

-----

1 point by sacado 6495 days ago | link | parent | on: Top 10 differences between Scheme and Arc

Yes, arc has arrays, in the libraries of the unofficial version.

-----

4 points by almkglor 6495 days ago | link

This "array" support is really for an abstract sparse array (with a hashtable implementation). I think what's being referred to is a "real array" (with a sequential-cells-of-memory implementation.)

-----

1 point by Jekyll 6495 days ago | link

That's a shame. I was all excited for a minute.

I guess I'll have start poking about in the source this weekend and see how hard it is to push the functionality up from the underlying scheme.

-----

1 point by almkglor 6495 days ago | link

While you're at it, try to see if it can be pushed up in lib/array.arc on the arc-wiki.

-----

1 point by sacado 6495 days ago | link

Oh, sorry. I guess it has to be added then :)

-----

3 points by sacado 6495 days ago | link

Do you think it is the right thing ? If so, I'll push it to the git. Nothing amazing there, just mzscheme vectors that can be called as hash tables, lists or string. It's got a constructor (vec) and responds to len. Any further function can (should) be written in Arc.

  arc> (= v (vec 10))
  #10(nil)
  arc> (= (v 1) 0)
  0
  arc> (len v)
  10
  arc> (v 0)
  nil
  arc> (v 1)
  0
  arc> (v 10)
  Error: "vector-ref: index 10 out of range [0, 9] for vector: #10(nil 0 nil)"

-----

2 points by almkglor 6495 days ago | link

Looks good. I vote for "push".

Edit: Although it might (?) be better in the lib/array.arc, unless of course it's already integrated into ac.scm...

Edit2: Also, I hope (vec ...) is a function, not a macro or special form, so that existing code that uses vec as a local variable for a collection, or as a function, can still work.

-----

2 points by sacado 6495 days ago | link

It can't be put in a .arc file, since it is pure scheme code. Further functions dealing with vectors should go in lib/array.arc, however. And yes, vec is a function.

-----

2 points by Jekyll 6494 days ago | link

That's awesome, but I've just lost all my motivation to learn git.

Nice work :D.

-----

1 point by sacado 6494 days ago | link

It is still very basic. Many utilitary functions could be added on top of that if you want :)

-----

1 point by sacado 6494 days ago | link

pushed. type on a vector also returns 'vec.

-----

3 points by sacado 6495 days ago | link | parent | on: Top 10 differences between Scheme and Arc

arc has a tendancy to removes parentheses : e.g. in "cond" and "let"

-----

More