Arc Forumnew | comments | leaders | submit | tokipin's commentslogin
2 points by tokipin 6359 days ago | link | parent | on: Learningcurve of LISP?

you don't have to write programs in a functional style. write them in whatever way they are most natural. though i agree with/let are kind of ookie at first

in my case what happens in languages is i hit a ceiling. in some languages i hit it right away, in others it takes a week or two. the worst ceiling imo is lack of first-class functions. beside that, code-as-data is another major lisp benefit. just consider lisp a language with ceilings substantially higher than most other languages

most of all i recommend having a significant project to write regardless of what language you're learning

-----

1 point by tokipin 6359 days ago | link | parent | on: small problem: (def power (nbr power)...

take a look at http://arcfn.com/doc/iteration.html for a list of different iteration functions. since you aren't using the x variable in those for loops there, you could just use repeat:

  (repeat (abs pow) ... )
here's my version:

  (def power (nbr pow)
     (withs (acc 1.0
             power+ (fn (times)
                        (repeat times
                            (zap * acc nbr))
                        acc))
            (if
              (> pow 0)
                    (power+ pow)
              (< pow 0)
                    (/ 1 (power+ (- pow)))
              1)))

-----


in the meantime i have devised a clever scheme i call "natural coercion":

  arc> (with (x 0 y 0.0)
          (is (+ x 0.0) (+ y 0.0)))
  t
it can be toolified as:

  (def eq args
      (apply is (map [+ _ 0.0] args)))

-----


as sacado wrote, you would write it:

  (if (is x 0)
      1
      2)
a nifty thing here is that the if expression returns the value of whichever expression is selected, so you can do:

  (prn (if (is x 0)
      1
      2))
which would be the equivalent of the algol:

  print if x==0
      then 1
      else 2
which would print either 1 or 2. same goes for any other form, including such things as case statements

also, check out the tutorial. despite it being being in .txt (probably for formatting purposes,) it's actually good:

http://ycombinator.com/arc/tut.txt

ken's reference site is also darn handy:

http://arcfn.com/doc/index.html

-----

1 point by sacado 6360 days ago | link

Yep. if actually behaves likes the ?: operator in C

  printf ("%d\n", x == 0 ? 1 : 2);

  (prn (if (is x 0) 1 2)

-----

1 point by tokipin 6360 days ago | link | parent | on: Arc on Windows, trouble installing

here's my batch file:

  cd "c:\documents and settings\account\desktop\arc2"
  mzscheme -m -f "as.scm"
the cd seems to be necessary. my guess is mzscheme takes note of the directory you launch things from, and relative file paths in the arc implementation are considered relative to where you launched the command, not relative to the folder as.scm is in

though i don't use a batch file anymore. not after i implemented a nice automated paste-this-code-from-Vim-to-the-REPL AutoHotkey script

-----

2 points by eds 6360 days ago | link

You can solve the cwd problem by passing a "--load-cd" parameter to mzscheme:

  mzscheme --no-init-file --mute-banner --load-cd C:\path\to\arc\as.scm

-----


wow lol. same name and everything. i guess it's not such an uncommon concept. i think i got the idea from anaphoric macros

thanks for pointing it out

[edit]it looks like there is only one global 'that, so it is unusable in functions. it seems more of a REPL mechanism at the moment. i guess to implement it in the spec would require wrapping things in (let that ...), or having it in the core

-----


is there a place to get the code for anarki without using my email? i'm curious about the implementation

-----

5 points by kens2 6375 days ago | link

See my article http://arcfn.com/2008/02/git-and-anarki-arc-repository-brief... for information on how to access anarki, in particular "Browsing Anarki without git".

-----

2 points by tokipin 6385 days ago | link | parent | on: Alternate form of fn

> > Simplification!? You seem confused. We have two concepts here. Using one symbol for two concepts does not combine two concepts into one.

i don't think these are distinct concepts. to me they are the exact same thing except in one case we're attaching a name to what we're making, and in the other we aren't. i can see how people familiar with lisp might see essentially 'lambda' and 'set' in the forms, but on the surface 'fn' and 'def' are very similar

i see the need for say, 'and' and the anaphoric 'aand', but to me def is so redundant with fn i actually do use that (= name (fn (x) ...)) form someone mentioned here

> > Again, overloading should be used sparingly, and only when the concepts are related in a certain way that I won't bother trying to articulate right now.

i agree, but again i don't think this is an inappropriate case. what i would like to see in Arc is something that Lua does in various places. the best example is its tables, which are simultaneously arrays, hash tables, and with its metatable system, any other structure you can think of from multiple-inheritance objects to arbitrarily-linked lists. and they act respectively depending on how they're used. eg if you use a table as an array it will iterate fast. the result is that the programmer is relieved of the details of choosing and using structures, and can instead focus on actually using them

is Lua's implementation of tables more sophisticated than arrays, hash tables, etc would have been individually? definitely. but it relieves the programmer of a lot of thought that is able to focus on something else. tables are definitely simpler than if their functionality was spread out, yet no functionality is lost compared to such a model. in fact, functionality is gained through the flexibility

by upping the sophistication underneath, a language can become simpler. if you only rely on the sort of simplicity brought about by a pure axiomatic approach, you get a sort of "assembly" simplicity. is MOV DX,8 simple? yes, but for naught

(not to blitzkrieg with text, but i thought i would explain the philosophy in one place)

> > for certain things like varargs

full varargs would be the only alteration

> > Doesn't that hurt your eyes?

yes, which is why i proposed another syntax. someone may be able to come up with something better. i use full varargs commonly so it wouldn't be easy for me to let go of the current syntax either

-----

2 points by eds 6385 days ago | link

It is true though that whenever you overload an operator you depend on the programmer understanding more about a single operation. Thus by definition overloading increases the complexity of a language.

Please see (and refute if you like) my comment at http://arclanguage.org/item?id=5213 .

There is some significant complexity in setting a variable. Note the current existence of four (or more) different forms of 'fn: 'fn (anonymous), 'afn (capturing 'self as a local name), 'rfn (using a user defined local name), and 'def (using a user defined global name). All these forms exist for the purpose of creating functions, but they each has a different way of setting varaibles.

How do you capture that complexity if you want to start combining them into a single operation? Do you just ignore everything except 'fn and 'def and say the user can type the extra character for 'afn and 'rfn? That seems rather inconsistent.

-----

1 point by tokipin 6385 days ago | link

> > It is true though that whenever you overload an operator you depend on the programmer understanding more about a single operation. Thus by definition overloading increases the complexity of a language.

that's if we're looking at it from the perspective of the operator. but if we look at it from the perspective of an expression, i think it is simpler. to illustrate: one of the nice examples on the front page of ruby-lang.org is the following (keeping their comments):

  # Ruby knows what you
  # mean, even if you
  # want to do math on
  # an entire Array
  cities  = %w[ London
                Oslo
                Paris
                Amsterdam
                Berlin ]
  visited = %w[Berlin Oslo]
 
  puts "I still need " +
       "to visit the " +
       "following cities:",
       cities - visited
if we look at it from the perspective of the operators, we see we've overloaded + and - for non-numeric types. however, if we look at it from the perspective of the programmer as they are writing those lines, we see that the programmer just wants to say "remove the cities i've visited from the cities i have to visit," and "cities - visited" is almost a direct translation of that. it makes sense. the fact that that operator happens to be overloaded from another domain is irrelevant. the context secures the role of the operator

-----

1 point by Jesin 6379 days ago | link

There is no syntax for varargs. Destructuring argument lists are very simple and easy to understand once you understand the structure of Lisp code. What you're proposing is taking away the ability to manipulate s-expressions as they are just to free up another name that would rarely be used anyway.

-----

1 point by tokipin 6378 days ago | link

yes, i thought of it that way, but what about the dot operator? (def fun (a . b) ...) isn't called like this: (fun (1 . 2 3))

and the optional args parameter. (def fun (a (o b)) ...) isn't called like this: (fun (1 (o 2)))

and i don't see how changing the single case of varargs takes away the ability to manipulate expressions as they are. it alters it for that one case

-----

1 point by tokipin 6386 days ago | link | parent | on: "while" with terminal test...

i would use something like (based on the rfn idea):

  (= a 0)
  
  ((afn ()
     (pr ++.a)
     (if (isnt a 8) (self))))

-----

3 points by drcode 6386 days ago | link

right- as I mentioned in the other comment, this is less cumbersome with "drain"

  (= a 0)
  
  (drain (do (pr ++.a)
             (isnt a 8)))

-----

3 points by almkglor 6385 days ago | link

shorter thus:

  (drain:do
    (pr ++.a)
    (isnt a 8))

-----

4 points by tokipin 6386 days ago | link | parent | on: Possible bug in News Code

probably to discourage commenting about URL submissions, which would confuse voting for the article (nice URL, shitty comment,) give a higher presentation priority to the submitter's comment, muddy up the analysis of the URL, and prematurely guide conversation

-----

More