Arc Forumnew | comments | leaders | submit | globalrev's commentslogin
1 point by globalrev 6240 days ago | link | parent | on: git, anarki, windows and ark.help!

C:\Users\saftarn\Desktop\myanarki\nex3-arc-20af2f3fe921faeca2048d1d932abcdae2a916b4

so i have that untared there now.

trying to run as.arc i get: procedure application: expected procedure, given: #f; arguments were: #<struct:fun-syntax> #<syntax:C:\Users\saftarn\Desktop\myanarki\nex3-arc-20af2f3fe921faeca2048d1d932abcdae2a916b4\ffi.scm:18:14>

i ran arc-exe.scm and now i can run arc in drscheme.

so now im running anarki in dr scheme right?

what was this GIT stuff i downloaded?

i thought it was some sort of IDE?

what do you use to edit/compile? is there something better than DrSceheme?

-----

4 points by croach 6239 days ago | link

Not sure if you're still reading this thread or not, but I thought I would try to clear up some of the questions you have here for you.

> so now im running anarki in dr scheme right?

Well, not exactly. MzScheme is the name of the Scheme programming language implementation that you are running anarki in, DrScheme is basically a nice GUI front end to the MzScheme language.

> what was this GIT stuff i downloaded? i thought it was some sort of IDE?

No, Git is not an IDE. It is software that is used to manage source code. In other words, using Git, you get a history of changes made to your source code allowing you to rollback changes and create new branches where you can develop new features without fear of breaking the currently working build of your software. The reason you downloaded it is because it is the source control software that the Anarki developers are using to manage the Anarki source code, so you need it to get a copy (i.e., a clone) of the current working version of Anarki.

> what do you use to edit/compile? is there something better than DrSceheme?

Everyone uses MzScheme to compile and execute Arc code, because that is the language that Arc was written in. There are other implementations of Arc on the JVM (aka Java Virtual Machine) and another that compiles to C, and I believe one in Common Lisp, but none of these are official implementations of Arc (i.e., created by Paul Graham). As for editing Arc code, well you can use whatever you want to edit it. Personally I'm an Emacs fan, so I use it for all of my editing, but I'm sure Vim, TextMate, etc., etc. would do just as well. If you are looking for an editor in which you can also execute your code, then Emacs or DrScheme should work.

I hope that clears up a few of your questions for you, good luck in your studies.

-----

1 point by globalrev 6239 days ago | link

ty very much, very appreciated.

-----

1 point by globalrev 6240 days ago | link | parent | on: git, anarki, windows and ark.help!

thanks.

-----


is it possible to do a tail-recursive power-function? would it then be faster than both or still slower than the normal recursive function?

-----

3 points by sacado 6241 days ago | link

Not tested, but it should work and is tail-recursive :

  (def power (nbr pow res)
    (if (is pow 0)
	    res
        (> pow 0)
            (power nbr (- pow 1) (* nbr res))
	(< pow 0)
            (power nbr (* -1 pow) (/ 1 res))))
Not sure for the case where (< pow 0), though. Just run the tests, but I think the tail-recursive function is at least as fast as the iterative one. Actually, in fine, iterative code is transformed into its tail-recursive equivalent : code involving for is transformed as a bunch of tail-recursive functions for example.

-----


is possible to make any of the 2 functions faster?

-----

2 points by cchooper 6241 days ago | link

You don't need to check that pow is less than zero in that last case.

  (def power (nbr pow)
    (if (is pow 0) 1
        (> pow 0)
	    (let acc nbr
    		(for x 1 (- pow 1)
        		(= acc (* acc nbr))) acc)
	(let acc 1
    	    (for x pow -1
		(= acc (/ acc nbr))) (/ acc 1.0))))

  (def power (nbr pow)
    (if (is pow 0) 
	    1
        (> pow 0)
	    (* nbr (power nbr (- pow 1)))
	(/ 1 (power nbr (* -1 pow)))))
Of course, if you want it to be really fast...

  (time (expt 234 34445)) => 101 msec.

-----

1 point by globalrev 6235 days ago | link

how can it be so much faster? its written in C or something? its built in the language somehow i guess, its not possible to recreate for me by writing a def?

-----

1 point by sacado 6235 days ago | link

It is probably written in C and does not check its args every time it is called. Basically, every time you call 'is, '<, '+, or any other primitive operation, it checks whether its arguments are numbers, then performs the operation. All these checks are useless since, within the body of your function, you know the type of your args are numbers, but you cannot avoid them anyway. Optimization will come, later :)

-----


ty very much for all the answers, very hepful.

-----


ah solved it now by reversing the variables. but lets say you have a function where you dont know before hand, how would you solve that? edit: changed variablename too.

  (def power (nbr pow)
    (if (is pow 0)
        1
        (if (> pow 0)
	    (let acc nbr
    		(for x 1 (- pow 1)
        		(= acc (* acc nbr))) acc)
	    (let acc 1
    		(for x pow -1
			(= acc (/ acc nbr))) (/ acc 1.0)))))

-----

1 point by tokipin 6241 days ago | link

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)))

-----


  (let acc 1
    		(for x 0 6 23456 666
			(= acc (/ acc 2))) acc)
why is the 23456 666 ignored? how can i just insert extra stuff there and nothing happens? where does it go, what can i do with it?

the problem with the func is the step, it need to subtract 1 and not step 1 at a time.

-----

1 point by cchooper 6241 days ago | link

They aren't ignored, they just don't do anything. for can take any number of arguments: the first is the symbol, the second the start value, the third the end value, and the rest are all the body of the loop. They all get executed in every iteration. For example:

(for x 0 6 (prn 2345) (prn 666) (= acc (/ acc 2))) acc)

produces

  23456
  666
  23456
  666
  23456
  666
  23456
  666
  23456
  666
  23456
  666
  23456
  666
  1/128

-----


works for (power 5 0), (power 5 2) but not (power 5 -2)

raising power to a negative number returns 1.

-----

1 point by wfarr 6241 days ago | link

Ah - I'll take a gander at that.

-----

1 point by globalrev 6241 days ago | link | parent | on: Learningcurve of LISP?

i have read somewhere that you should keep the functional part of a program as small as possible because it makes it too hard to follow if its big.

but LISP is basically all functiosn right?

so you think whoever wrote/said that was a m?

-----

4 points by cchooper 6241 days ago | link

I've never heard anyone say that before. It sounds crazy to me.

Are you sure they weren't talking about keeping individual functions small?

-----

1 point by globalrev 6241 days ago | link

could be, not sure and have no link.

-----


without thinking i see i used a input witht he same name as the function.

this doesnt seem to cause a problem though. so it is ok or can be a problem?

-----

1 point by wfarr 6241 days ago | link

I believe so.

Because the 'def macro uses '= to define functions, variables and functions are occupying the same namespace (sort of).

For example:

  (def foo () (prn "bar"))
is expanded to:

  (= foo (fn () (prn "bar")))
For example:

  > (def foo () (prn "bar"))
  #<procedure: foo>
  > (= foo "foo")
  "foo"
  > (foo)
  Error: "procedure ...r/src/arc/ac.scm:1224:11: expects 2 arguments, given 1: \"foo\""
Make sense?

Though, that may not affect your usage here since power is just an argument and not a variable itself.

-----

1 point by cchooper 6241 days ago | link

In this case it's not causing a problem. You're allowed to give parameters whatever name you want, but if you name the parameter after the function then you can't call the function from within itself because the name will now refer to the argument.

So if you don't need to call the function recursively, there's no harm. It's just a bit confusing.

-----

More