Arc Forumnew | comments | leaders | submit | zck's commentslogin
2 points by zck 3850 days ago | link | parent | on: On Lisp - Figure 18.5 matching function

I see that you've got some code that's working, but if you want to extend it more, I'll recommend a unit test library I wrote. You might find some unit tests helpful to know when your code is working. The library is https://bitbucket.org/zck/unit-test.arc/ .

You'll make unit tests inside a test suite, like so:

    (suite match
           single-specific-element (assert-same '(t t) (match '(a) '(a)))
           single-variable-symbol (assert-same '((?x 3) t) (match '(?x) '(3))))
And you'll run them like this:

    (run-suite match)

-----

2 points by cthammett 3850 days ago | link

Thanks this will be very useful.

-----

3 points by zck 3895 days ago | link | parent | on: Using arc with Emacs

I open up a shell in Emacs (M-x shell), then run Arc manually. You have to explicitly `load` things from the REPL; there isn't any SLIME-like communication between other buffers and the shell. This doesn't seem to work right now with Anarki, but it does with Arc3.1

-----

3 points by akkartik 3895 days ago | link

As a tangent, I use vim, tmux and https://github.com/jpalardy/vim-slime to send expressions to the repl.

-----

2 points by zck 3895 days ago | link

I realized just now that you're using Windows, on which I have no idea if Anarki works inside Emacs. So you should try it and see what happens.

-----

2 points by zck 3901 days ago | link | parent | on: Reading a text file into a list or an array

untested code:

  (def read-all (filename)
       (w/infile file filename
                 (drain (readline file))))
`drain` executes its argument repeatedly until it returns nil. (https://arclanguage.github.io/ref/iteration.html#drain)

`readline` returns nil when there's nothing more to read (https://arclanguage.github.io/ref/io.html#readline)

-----

2 points by zck 3900 days ago | link

Now that I've been able to test it, this works, as long as you don't have empty lines in your file. If you do, it works...oddly:

This file:

    This is the first line.
    After this line there is an empty line.
    
    After this line there are two empty lines.
    
    
    This is the last line.

results in this list:

    arc> (read-all "/home/zck/test.txt")
    ("This is the first line." "After this line there is an empty line." "\nAfter this line there are two empty lines." "\n" "This is the last line.")
Note how the newline after the first empty line gets glommed onto the line after it? Yech. But it does work exactly as expected if each line is nonempty.

-----

2 points by akkartik 3900 days ago | link

That is indeed quite lame: http://arclanguage.github.io/ref/io.html#readline

Edit 8 minutes later: seems to work fine for me on anarki.

  arc> (fromfile "x" (drain:readline))
  ("This is the first line." "After this line there is an empty line." "" "After this line there are two empty lines." "" "" "This is the last line.")
  arc> (fromstring "\n\na\nc\n\nd" (drain:readline))
  ("" "" "a" "c" "" "d")
Were you running arc3.1 or something?

-----

2 points by zck 3899 days ago | link

Yeah, I run arc3.1 for several reasons -- including that anarki doesn't work in Emacs's shell, and I haven't taken the time to figure out^1 why: my hypothesis is that simply removing rlwrap would fix it, but I so rarely use Arc these days I haven't dealt with it.

[1] Nor have I taken the time to respond to your emails from months ago. I'm sorry about that; it's related (among other things) to some general malaise I'm trying to deal with.

-----

3 points by rocketnia 3898 days ago | link

I think this thread is when the bug was raised and fixed: http://arclanguage.org/item?id=10830

-----

1 point by jsgrahamus 3898 days ago | link

Here are some of the results I got:

  Use (quit) to quit, (tl) to return here after an interrupt.

  arc> (def read-all (filename)
       (w/infile file filename
                 (drain (readline file))))
  #<procedure: read-all>
  arc> (read-all "c:\users\steve\desktop\mccf2.txt")
  Error: "UNKNOWN::112: read: no hex digit following \\u in string"
  arc> Error: "_ersstevedesktopmccf2: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:\users\steve\desktop\iiv.txt")")\r\n(read-all "
  arc> #<procedure>
  arc> (read-all "c:\users\steve\desktop\iiv.txt")")\r\nRread-all "
  arc> #<procedure>
  arc> (read-all "c:\users\steve\desktop\xxx2.m3")")\r\n(read-all "
  arc> #<procedure>
  arc> (read-all "c:\users\steve\desktop\mccf.scm")")\r\n(read-all "
  arc> #<procedure>
  arc> (read-all "c:\users\steve\desktop\jsg.xxx")")\r\n(read-all "
  arc> #<procedure>
  arc>

-----

1 point by rocketnia 3898 days ago | link

This is probably what you need:

  (read-all "c:\\users\\steve\\desktop\\mccf2.txt")
What you wrote was a string with \u, which didn't follow through with a complete Unicode escape sequence:

  (read-all "c:\users\steve\desktop\mccf2.txt")
Once the reader got to \u, it raised a parse error, and the REPL continued to process the rest of your input as a new command:

  sers\steve\desktop\mccf2.txt")
The " here started a string, and your next command was interpreted as part of that string.

  (read-all "c:\users\steve\desktop\iiv.txt")
So here we have the end of a string, followed by the symbol c:\users\steve\desktop\iiv.txt followed by the start of another string.

-----

3 points by jsgrahamus 3898 days ago | link

   Use (quit) to quit, (tl) to return here after an interrupt.
   arc> (def read-all (filename)
          (w/infile file filename
                    (drain (readline file))))
   #<procedure: read-all>
   arc> (read-all "c:\\users\\steve\\desktop\\mccf2.txt")
   Error: "_R: undefined;\n cannot reference undefined identifier"
   arc> 1
   1
   arc> (read-all "c:/users/steve/desktop/mccf2.txt")
   Error: "_R: undefined;\n cannot reference undefined identifier"
   arc>

-----

2 points by jsgrahamus 3898 days ago | link

  C:\Users\Steve\Desktop>type mccf.scm
  (define x)
  (call-with-input-file "c:/users/steve/desktop/mccf.txt"
    (lambda (input-port)
      (let loop ((x (read-char input-port)))
        (if (not (eof-object? x))
            (begin
              (display x)
              (loop (read-char input-port)))))))
  C:\Users\Steve\Desktop>

  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> (def read-all (filename)
            (w/infile file filename
                      (drain (readline file))))
  #<procedure: read-all>
  arc> (read-all "c:/users/steve/desktop/mccf.scm")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:/users/steve/desktop/mccf.scm")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:\\users\\steve\\desktop\\mccf.scm")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc>

-----

3 points by rocketnia 3898 days ago | link

I've seen this before. What's happening, somehow, is that every time you write more than one line in a definition at the REPL in a Windows prompt, a capital R is being inserted at each newline. Arc compiles this to the Racket code _R, and when Racket executes this, it can't find the _R variable.

I seem to remember I used work around this by always pasting my multi-line definitions from a text editor rather than writing them directly at the REPL.

-----

3 points by jsgrahamus 3897 days ago | link

Thanks for mentioning this. Saw it in a racket repl, too. Reported it to the Racket Users list.

-----

3 points by jsgrahamus 3898 days ago | link

BTW, this is Windows 7x64.

I am pasting the definition into the arc cmd window.

-----

2 points by rocketnia 3898 days ago | link

Oh, sorry. Now that I test it, I realize I remembered incorrectly.

The only time I get those spurious R characters is when I paste code into the REPL and then press enter manually. I don't get them when typing multi-line definitions directly at the REPL, and I don't get them if the code I'm pasting already has a line break at the end.

So the habit I've formed is to make sure the code I'm pasting already has a line break at the end.

I notice this issue also happens on Racket 5.3.3 -- I'm a few versions behind -- and it does not happen in the REPLs for Node.js or Clojure. It's some kind of bug in Racket. (Hmm... Racket's port.c has a bunch of spaghetti code for CRLF processing. Maybe the bug's in there somewhere.)

-----

1 point by akkartik 3898 days ago | link

Oh I wonder if it's a linefeed-newline thing. I know "\r" is the code for linefeed, for example..

-----

2 points by zck 3898 days ago | link

As akkartik says, let's step away from the complex code, and get back to basics. Let's use dir-exists (https://arclanguage.github.io/ref/filesystem.html#dir-exists) to test out how to reference directories.

So let's just see if we can get a 't when we check the existence of C:\users

Here are the four things I'd try:

    (dir-exists "C:/users")
    (dir-exists "C://users")
    (dir-exists "C:\users")
    (dir-exists "C:\\users")
My money's on the first or last one working. (Obviously this assumes you _have_ a `C:\users` directory) I would similarly bet that you might need to capitalize the drive, even though Windows drive letters are case insensitive (https://msdn.microsoft.com/en-us/library/windows/desktop/aa3...). So if it doesn't work with lowercase letters, try it as above.

-----

2 points by jsgrahamus 3898 days ago | link

arc> (dir-exists "c:/users") "c:/users" arc> (dir-exists "c:\\users") "c:\\users"

-----

1 point by akkartik 3898 days ago | link

Very strange. What arc are you using?

Can you try it without the drain, just read the first line from the file?

Edit 10 minutes later: here's a few things I would try:

  ; a relative path with no slashes/backslashes
  (read-all "mccf2.txt")
  ; inline read-all
  (w/infile file "mccf2.txt" (drain (readline file)))
  ; try reading just the first line
  (w/infile file "mccf2.txt" (readline file))

-----

2 points by jsgrahamus 3898 days ago | link

This is arc 3.1

  C:\Users\Steve\Documents\Programming\Lisp\arc\arc3.1>type log.txt
  =====   11:52:29 AM
  =====   11:56:49 AM
  =====   12:10:19 PM
  =====   12:39:31 PM
  =====   1:08:54 PM
  =====   1:11:19 PM
  =====   2:14:21 PM
  =====   2:14:33 PM
  =====   12:36:29 PM
  =====   5:13:08 PM
  =====   9:56:43 AM
  =====   2:36:16 PM
  =====   4:23:45 PM
  =====   2:35:41 PM

  C:\Users\Steve\Documents\Programming\Lisp\arc\arc3.1>dir c:\log.txt
   Volume in drive C is TI105757W0A
   Volume Serial Number is 48C4-C0F7

   Directory of c:\

  12/17/2014  03:40 PM               271 Log.txt
                 1 File(s)            271 bytes
                 0 Dir(s)  61,392,650,240 bytes free

  C:\Users\Steve\Documents\Programming\Lisp\arc\arc3.1>

  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> (def read-all (filename)
         (w/infile file filename
                   (drain (readline file))))
  #<procedure: read-all>
    arc> (read-all "Log.txt")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:Log.txt")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:/Log.txt")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (read-all "c:\\Log.txt")
  Error: "_R: undefined;\n cannot reference undefined identifier"
arc>

-----

2 points by jsgrahamus 3898 days ago | link

This seems to be onto something!

  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> (def read-all2 (filename)
         (w/infile file filename))
  #<procedure: read-all2>
  arc> (read-all2 "Log.txt")
  Error: "_R: undefined;\n cannot reference undefined identifier"
  arc> (w/infile file "Log.txt" (drain (readline file)))
  ("===== \t11:52:29 AM\r" "===== \t11:56:49 AM\r" "===== \t12:10:19 PM\r" "===== \t12:39:31 PM\r" "===== \t1:08:54 PM\r" "===== \t1:11:19 PM\r" "=====\t2:14:21 PM\r" "===== \t2:14:33 PM\r" "===== \t12:36:29 PM\r" "===== \t5:13:08 PM\r" "===== \t9:56:43 AM\r" "===== \t2:36:16 PM\r" "===== \t4:23:45 PM\r" "===== \t2:35:41 PM\r")
  arc> (w/infile file "Log.txt" (readline file))
  "===== \t11:52:29 AM\r"
  arc>

-----

1 point by akkartik 3898 days ago | link

So it looks like the inlined version works, but wrapping it in a function doesn't? Very strange. Paste these lines one at a time into a fresh arc session and show me what you get in response to each line.

  (w/infile file "Log.txt" (drain (readline file)))  ; just to set a baseline
  (def foo (filename) (prn "AAA") (w/infile f filename (prn "BBB") (drain (do1 (readline f) (prn "CCC")))))
  (foo "Log.txt")
  (def foo (filename) (prn "AAA") (w/infile f filename (prn "BBB") (readline f)))
  (foo "Log.txt")

-----

2 points by jsgrahamus 3898 days ago | link

akkartik, here are the results.

  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> (w/infile file "Log.txt" (drain (readline file)))  ; just to set a baseline
  ("===== \t11:52:29 AM\r" "===== \t11:56:49 AM\r" "===== \t12:10:19 PM\r" "===== \t12:39:31 PM\r" "===== \t1:08:54 PM\r" "===== \t1:11\t2:14:21 PM\r" "===== \t2:14:33 PM\r" "===== \t12:36:29 PM\r" "===== \t5:13:08 PM\r" "=====\t9:56:43 AM\r" "===== \t2:36:16 PM\r" "M\r" "=====\t2:35:41 PM\r")
  arc> (def foo (filename) (prn "AAA") (w/infile f filename (prn "BBB") (drain (do1 (readline f) (prn "CCC")))))
  *** redefining foo
  #<procedure: foo>
  arc> (foo "Log.txt")
  AAA
  BBB
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  CCC
  ("===== \t11:52:29 AM\r" "===== \t11:56:49 AM\r" "===== \t12:10:19 PM\r" "===== \t12:39:31 PM\r" "===== \t1:08:54 PM\r" "===== \t1:11\t2:14:21 PM\r" "===== \t2:14:33 PM\r" "===== \t12:36:29 PM\r" "===== \t5:13:08 PM\r" "===== \t9:56:43 AM\r" "===== \t2:36:16 PM\r" "M\r" "===== \t2:35:41 PM\r")
  arc> (def foo (filename) (prn "AAA") (w/infile f filename (prn "BBB") (readline f)))
   *** redefining foo
  #<procedure: foo>
  arc> (foo "Log.txt")
  AAA
  BBB
  "===== \t11:52:29 AM\r"
  arc>

-----

1 point by akkartik 3898 days ago | link

I think rocketnia has figured it out. Does rocketnia's comment http://arclanguage.org/item?id=19137 make sense? Basically you shouldn't get an error if you type in this expression character by character, but you should if you paste it into an arc session without a trailing <enter>.

  (def read-all2 (filename)
    (w/infile file filename))
(Try it out each time as before by running (read-all2 "Log.txt"))

-----

2 points by jsgrahamus 3897 days ago | link

  arc> (def read-all (filename) (w/infile file filename (drain (readline file))))
  arc> (read-all "Log.txt")
("===== \t11:52:29 AM\r" "===== \t11:56:49 AM\r" "===== \t12:10:19 PM\r" "===== \t12:39:31 PM\r" "===== \t1:08:54 PM\r" "===== \t1:11:19 PM\r" "=====\t2:14:21 PM\r" "===== \t2:14:33 PM\r" "===== \t12:36:29 PM\r" "===== \t5:13:08 PM\r" "===== \t9:56:43 AM\r" "===== \t2:36:16 PM\r" "===== \t4:23:45 PM\r" "===== \t2:35:41 PM\r")

Thanks for that.

It does appear that the problem is with pasting into the repl. So, how does one hook up arc with Emacs?

Thanks to all those who chimed in with help. Great community here.

Steve

-----

1 point by jsgrahamus 3898 days ago | link

It doesn't seem to deal nicely with control characters. Not sure why the rest of the results are as they are.

-----

2 points by zck 3959 days ago | link | parent | on: Executing files in windows

This should work as long as foo.arc is in the same directory you're running Arc out of.

If your file is somewhere else, you'll have to specify the full path to it (warning: untested):

  arc> (load "C:\\Users\\Benben\\Documents\\foo.arc")

-----

4 points by zck 4005 days ago | link | parent | on: Arc Forum Maintenance

Cool! Glad to hear things are still happening. I'm sure we'd love to hear more about what's going on at YC with Arc.

-----

4 points by kogir 4005 days ago | link

The Hacker News codebase is in Arc, and will be for the foreseeable future. All the core domain work is done in it, and we write Arc code every day. When it makes sense for performance or practical reasons we call into Racket, but not frequently enough that we've even bothered exposing nice syntax for it (like anarki's $).

-----

5 points by akkartik 4005 days ago | link

I'm not sure if you're the best person to ask, but:

Is the arc currently running HN significantly different from the arc 3.1 c. 2009?

Any plans for a new arc release? :)

Any lessons you can share from your experiences scaling up HN? (Like the push to eliminate fnids, for example.)

-----

3 points by zck 4059 days ago | link | parent | on: After i changed something

I haven't been running the server in a while, but I have a few thoughts.

First, what version of anarki did you start with?

What were the edits you made? Does it work if you start the server without your changes?

What happens in the log before the errors?

What do you have to do to get the errors to occur? Is it upon server startup, or is it when you load a page in your browser, or try to register a user?

-----

2 points by tvvocold 4058 days ago | link

1,https://github.com/shader/arc-openshift is what i use in openshift

2,http://arclanguage.org/item?id=18840 i followed this and server works.

3,i only got openshift's log http://p.fdzh.org/paste/9jBPxB14

4,i donnot really know,after some days (maybe 5 or less) the server broken and could loaded,i think maybe the ab test from somebody?

ps:when server goes down i need to kill -9 the 80 port's pid and then restart app,but few days later it will happen again.

thx btw.

-----

1 point by akkartik 4057 days ago | link

Back when I ran an arc service I noticed it ran out of memory every few days. So I'd run the server in a loop on my shell, immediately restarting it if it died.

-----

1 point by tvvocold 4057 days ago | link

nice! but how to add a loop bash in openshift?

-----

1 point by akkartik 4057 days ago | link

Can you login to the server?

-----

1 point by tvvocold 4056 days ago | link

the reason maybe too much people came in , when i post a arc link to other website then i cannnot open arc site.

-----

1 point by tvvocold 4057 days ago | link

sure,then?

-----

1 point by akkartik 4056 days ago | link

First create a way to have arc automatically run (nsv) on startup. Then you can say this (assuming your shell is bash):

  $ while true; do arc server.arc; done
Now anytime your server dies it'll just come back up.

-----

3 points by akkartik 4055 days ago | link

I've updated the repository to make this easier. There's now a script called run-news to bring up the HN server.

  $ git pull
Now you should be able to run your server in a loop like this:

  $ while true; do ./run-news; sleep 5; done
Let me know if you run into trouble with this. I'll be around and more responsive for the next few days.

More notes, just for future reference:

1. run-news provides an interactive prompt, so you can make changes to the server without needing to restart it. Just remember to also modify news.arc otherwise your changes will be lost when the server dies next.

2. The sleep above is to help exit the server. If you quit the server as usual it'll just come up again. To bring it down, hit ctrl-c twice in succession.

3. I also fixed up the readme, which was abysmally out of date. Sorry about that.

-----

1 point by tvvocold 4053 days ago | link

thx,cool!

btw,i use https://github.com/shader/arc-openshift for openshift env,(not the https://github.com/arclanguage/anarki) how could i update it?

-----

1 point by akkartik 4052 days ago | link

arc-openshift installs anarki: https://github.com/shader/arc-openshift/blob/fa9def061/.open...

Just cd into the arc directory ($OPENSHIFT_DATA_DIR/arc, but I'm not sure how to deduce OPENSHIFT_DATA_DIR) and run:

  $ git pull

-----

1 point by tvvocold 4052 days ago | link

when i git pull i got

  error: Your local changes to the following files would be overwritten by merge:
    lib/news.arc
  Please, commit your changes or stash them before you can merge.
  Aborting

-----

1 point by akkartik 4052 days ago | link

Have you made any changes to news.arc? Mail me the output of this command, and I'll help you with the merge.

  $ git diff lib/news.arc

-----

1 point by zck 4090 days ago | link | parent | on: Sorry

Hear, hear. Even if we gift-wrapped a tarball of new code^1 , it wouldn't get on the server that runs this forum.

[1] tar -czf --include-bow new-arc.tgz arc/

-----


Congrats to you too!

What's the future path for emiya? It looks really cool, but it seems like you haven't done much with it since last fall.

-----

3 points by waterhouse 4138 days ago | link

Well, since you ask. :-) And since the judging is all done, I might as well update it. So. Currently things are broken up into "dyn-cont", which has the Arc interpreter, "arc-boot", which is the code the interpreter will run on startup, and "memory-system", which is where I'm prototyping the stuff the next version of "dyn-cont" will run on: fake assembly code, which is a preparation for writing real assembly code.

https://github.com/waterhouse/emiya/blob/master/arc3.1/inter...

https://github.com/waterhouse/emiya/blob/master/arc3.1/inter...

https://github.com/waterhouse/emiya/blob/master/arc3.1/inter...

-----


Certificates of Awesome were awarded to "exceptional participants that received a high score." It's the award one step below Second Price Winners.

The winners are here: http://lispinsummerprojects.org/winning-projects .

Waterhouse wrote an Arc interpreter on top of Arc with continuations, and first-class macros and first-class special forms. Scanning over his submission form (http://lispinsummerprojects.org/static/summer/250119.pdf), it also interestingly lets quasiquote be defined as a macro.

-----

2 points by akkartik 4140 days ago | link

This is great!! Congrats to both of you.

-----

3 points by zck 4143 days ago | link | parent | on: What is compiler can compile arc code???

Are you looking to _run_ arc? Follow the instructions here: http://arclanguage.github.io/

Or are you specifically looking for a compiler?

-----

2 points by zck 4143 days ago | link

To explain further: I ask if you're specifically looking for a compiler because some people think that the only way to run any code is with a compiler, or that specific languages require one. Absent a specific thing in a spec ("an implementation of AwesomeLanguage requires compilation or it can't be called AwesomeLanguage"), languages can be interpreted or compiled.

So if you're interested in compilers, and want to see one for Arc, that's fine. But the default way of running Arc is not with a compiler. If you just want to run Arc, follow the instructions above.

-----

2 points by akkartik 4143 days ago | link

Arguably arc is a compiler to scheme. ac stands for arc compiler I believe. The scheme might be interpreted or JIT-compiled.

-----

2 points by zck 4143 days ago | link

Well, fair enough. At some point, I really need to spend more time with Arc's internals.

-----

2 points by victor5133 4143 days ago | link

Thank you.

-----

More