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

I just went through this exercise as well. Once you define the server, you can then query it with this code:

    arc> (load "lib/client.arc")
    arc> (cdr (mkreq "http://localhost:8080/"))

reply

2 points by zck 3 days ago | link

Ooh, interesting! We might want to figure out a long-term documentation system for Anarki; the existing arclanguage.github.io documentation is for Arc 3.1. And while that's great, it's suboptimal for cases like this, because it says "...there is no support for outgoing network connections." (https://arclanguage.github.io/ref/networking.html).

reply

1 point by akkartik 3 days ago | link

Yeah, there's a reason why the documentation isn't linked on the right side at http://arclanguage.github.io :/

reply

2 points by christianbryant 3 days ago | link

How about UDP calls? I sucked this CL snippet a while back (sorry I don't have the author info at hand). Creates a socket, sends data and receives data:

  (defun create-client (port buffer)
     (let ((socket (usocket:socket-connect "127.0.0.1" port
					 :protocol 
                                         :datagram
					 :element-type 
  '(unsigned-byte 8))))
    (unwind-protect
	 (progn
	   (format t "Sending data~%")
	   (replace buffer #(1 2 3 4 5 6 7 8))
	   (format t "Receiving data~%")
	   (usocket:socket-send socket buffer 8)
	   (usocket:socket-receive socket buffer 8)
	   (format t "~A~%" buffer))
      (usocket:socket-close socket))))

reply


Thanks for the pointer to IOLib! We don't have anything like it, but there is an http client: https://github.com/arclanguage/anarki/blob/master/lib/client.... It also has unit tests, so is unlikely to have suffered bitrot.

I've built an http client several times in my life, particularly in Wart (https://github.com/akkartik/wart/blob/master/073http_get.war...) and in Mu (http://akkartik.github.io/mu/html/092socket.mu.html#L35). So I'd be happy to help if you want to try to put something together yourself.

reply

2 points by christianbryant 3 days ago | link

Thanks, Kartik!

I appreciate the info. I was actually just looking at Mu since I cloned that code for review recently. Since the framework I'll be doing this in is a testing suite, Mu may be the best model for me to follow.

Since I'm focused on UDP, Looking at comments in ac.scm in Arc, I realized MzScheme might hold the answer - there are plenty of UDP functions in those libraries.

Let me poke around a but and I'll shoot you an email if I have something to pass by you for opinion.

reply

2 points by christianbryant 3 days ago | link

It's about now I realize I'm using an old Arc (hence the MzScheme reference). Moving to arc-nu and Racket (as noted by Zachary) which provides all the UDP I need ;-)

I'll spend some time on this - appreciate the responses.

reply

3 points by akkartik 2 days ago | link

Great. Just one caveat: we tend to have more experience with just Anarki (https://github.com/arclanguage/anarki) which is also using the latest Racket.

If you're thinking of https://github.com/arclanguage/arc-nu, the author hasn't been active here in a while, so you may need to ping Pauan separately.

reply

2 points by christianbryant 2 days ago | link

Ah... thanks for that note. I am working with Anarki primarily now as noted earlier for News and similar, but also didn't catch on that it was the main working model here.

reply


Great to see! What's gotten you interested in it at the moment?

reply

3 points by christianbryant 5 days ago | link

My immediate interest is in "News". I was seeking a codebase to work from that would put me in a similar space as HN in look and function. I came across Anarki and was pleased to see it was related to Arc which I have recently been playing with.

My longterm interest is in shifting my mental focus to a more Lisp-oriented way of programming and thinking. I'm not a programmer by trade; I am a software tester and scripter, mostly. I use Python typically, but after working on an OS build I had to learn Guile and Emacs Lisp quickly. I fell in love with Lisp and Scheme due to this experience.

Arc interest came about after reading about it on Paul Graham's website. I'd worked through a portion of Practical Common Lisp by Seibel and decided to try out Arc. It felt right. Since I also happen to work in the Information Security space, I have ideas that for the most part feel like Lisp is the right language, but I will need to become more proficient. Anarki feels like a good place to start to get there from.

Side note: An an automation tester at UCLA working with SenseTalk via Eggplant, I came across Mu while researching alternatives to Eggplant in areas it fails to provide results, such as passing and receiving AIX system calls, or validating logs are being written to. Mu has caught my attention for the longterm, as well, so kudos for both Anarki and Mu.

reply

2 points by akkartik 4 days ago | link

Thanks for the kind words, and for the pointer to SenseTalk and Eggplant! I'd never heard of it, so I went off to correct that and ended up at this paper after a few clicks:

"Software Verification of Orion Cockpit Displays", https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/201700...

Very interesting. Though the thought of NASA just using Python and a proprietary solution seems worrying. Maybe it's just for the test harness and other scaffolding, not code that will actually run in orbit.

reply

2 points by christianbryant 3 days ago | link

I know lots of large organizations use Eggplant but this paper is a new one to me. Thanks - had to share this with my co-workers! Everyone seems enthused we share a testing tool with NASA ;-)

I work in Healthcare and we use Eggplant to test a large functional area of our Electronic Health Record (EHR). Like many automation tools, much of the success of the testing comes down to the testing team and how they develop the scripts.

I approach automated scripting design the way I approach programming an app, so I am pretty formal and diligent, I think. Hopefully I am taking lessons learned from Lisp and applying them to my work in automated testing to make the best tests I can.

reply

2 points by christianbryant 5 days ago | link

It's kismet, perhaps, but I also worked on a project called Arc some 9 years ago before I found - well, Arc. It was a build tool chain written in Scheme, developed by Gregor Klinke. I was at the height of my interest in Lisp and Scheme back then, and I liked the idea of this project for potentially building a Software Configuration Management system oriented to Scheme and Lisp.

Looking back at this project with new eyes, perhaps swapping out Scheme for Arc, I wonder...

Arc build tool project http://savannah.nongnu.org/projects/arc

reply

2 points by akkartik 27 days ago | link | parent | on: Problem with assignment

Yes, this is a bug in Arc 3.1: http://arclanguage.org/item?id=17699 [1]

Use Anarki or Anarki's stable branch. The latter is like Arc 3.1 but with a couple of bugfixes.

More details: http://arclanguage.github.io

[1] via google: 'site:arclanguage.org string-set contract violation' :D

reply

2 points by jsgrahamus 25 days ago | link

Windows 10: When I put the anarki folder in D:\, calling it worked fine.

However, when I put the folder in D:\Steve - D\Apps\, I got the following: D:\Steve - D\Apps\anarki>arc.cmd default-load-handler: cannot open module file module path: #<path:D:\Steve> path: D:\Steve system error: The system cannot find the file specified.; errid=2

I figure it has to do with spaces in the pathname, but unsure how to fix it.

reply

2 points by akkartik 25 days ago | link

It sounds like we need to put quotes around the '%arc_dir%boot.rkt' in arc.cmd: https://stackoverflow.com/questions/1851012/set-a-path-varia...

Can you check if that fixes it?

reply

2 points by jsgrahamus 25 days ago | link

That did it.

Thanks, akkartik!

reply

1 point by akkartik 24 days ago | link

Thanks! Wanna submit a Pull Request? ^_^

Not a big deal, I can do it too. But if it's easy you'd get to add your name to the repo :) Let me know.

reply

2 points by jsgrahamus 24 days ago | link

Sure. Never done such before. Where are instructions for it?

reply

1 point by akkartik 23 days ago | link

Maybe this will get too involved. Do you have experience with git, say making commits and so on?

Wanna switch to email? If you click on my username, my profile has my email address.

reply


My experience: https://lobste.rs/s/v17gol/switching_sublime_text_from_vim_2...

reply

2 points by hjek 49 days ago | link

Nice write-up.

I think regardless of whether it's really an editor to use on daily basis, it's quite interesting to see any new take on editor keyboard interaction.

reply

4 points by akkartik 112 days ago | link | parent | on: List comprehensions in Arc

musk_fan, your initial attempt inspired me to build on it :) Now that we can enumerate from a start number to an end, I hanker after something more comprehensive. Also, after reading malisper's description of iterate at http://malisper.me/loops-in-lisp-part-3-iterate, I thought I'd try to mimic its syntax, in hopes that it'll fit better with a Lisp and be extensible.

Here's what I ended up with: http://akkartik.name/post/list-comprehensions-in-anarki. Is the description clear?

-----

2 points by akkartik 86 days ago | link

List comprehensions are now in Anarki: https://github.com/arclanguage/anarki/commit/b7155e56a6

-----

4 points by akkartik 116 days ago | link | parent | on: List comprehensions in Arc

Yes, Arc doesn't come with list comprehensions. But it sounds like a fun exercise to build say a collect macro:

    (collect x for x in xs if odd.x)
I think it may be similar to the loop macro in Common Lisp. There's a Common Lisp implementation of loop at https://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/... (via http://malisper.me/loops-in-lisp-part-2-loop by malisper)

-----

3 points by musk_fan 112 days ago | link

I wrote a simple version that only works like so (l 0 9) == '(0 1 2 3 4 5 6 7 8 9):

     (def l (start end)
       (let lis `(1)
         (pop lis)
         (while (<= start end)
           (= lis `(,@lis ,start))
           (++ start))
         lis))
The (collect ...) structure is really cool; I'd forgotten about that; it's been awhile since I touched CLisp

-----

2 points by akkartik 112 days ago | link

Great! A few comments:

1. Is there a reason you start with `(1) and then pop? Why not just initialize lis to nil?

2. Here's a slightly more idiomatic implementation (also more efficient, because it avoids deconstructing and reconstructing lis on every iteration):

    (def l (start end)
      (accum acc
        (for i start (<= i end) ++.i
          acc.i)))
Read more about accum and for:

    arc> (help accum)
    arc> (help for)
(I'm assuming Anarki in the above example. The Arc version is slightly different.)

-----


Wow, perhaps I should become an APL programmer. (My links below are probably familiar to everyone here, so forgive the shameless replugs. I'm mostly just working through commonalities for my own self.)

"[There is] a sharp contrast between Subordination of Detail and Abstraction as the term is commonly used in Computer Science. Iverson’s notion of subordination is the elimination of notational obligations through the use of generalization, systematic extension, and implicit guarantees. The usual notion of abstraction is the means by which 'API' barriers may be introduced to implement conceptual frameworks that suppress underlying implementation considerations in order to allow a black box reasoning at a different, non-native abstraction level."

I'm very partial to this point, but confusingly I've been calling Iverson's notion of subordination of detail "abstraction", and Iverson's notion of abstraction "service" [1] or "division of labor" [2]. Though lately I try to avoid the term "abstraction" entirely. That seems on the right track.

Regardless of terminology, this is a critical distinction.

[1] http://akkartik.name/post/libraries [2] http://akkartik.name/post/libraries2

---

"Common practice encourages decomposing a problem into very small components, and most programming languages emphasize a clear picture of a small piece of code in isolation. APL emphasizes finding ways of expressing solutions around the macro-view of the problem."

Compare http://akkartik.name/post/readable-bad

---

Quoting Knuth: *"I also must confess to a strong bias against the fashion for reusable code. To me, re-editable code is much, much better than an untouchable black box or toolkit."

Compare me: "Watch out for the warm fuzzies triggered by the word 'reuse'. A world of reuse is a world of promiscuity, with pieces of code connecting up wantonly with each other. Division of labor is a relationship not to be gotten into lightly. It requires knowing what guarantees you need, and what guarantees the counterparty provides. And you can't know what guarantees you need from a subsystem you don't understand."

---

OMG, he's talking about "big picture" and "optimizing for the rewrite" I call the latter rewrite-friendliness at http://akkartik.name/about. And "big picture" is in the navbar on the right of my side.

---

Ok, that's enough replugging. The most tantalizing idea for me here is to try to get structure to do some of the heavy lifting that names do in more conventional languages.

As a final note, this link somebody showed me today seems really relevant: https://iaminterface.com/cognitive-artifacts-complementary-c...

-----

3 points by jsgrahamusarc 139 days ago | link

Good to see that your minds have been moving along the same tracks.

-----

4 points by akkartik 150 days ago | link | parent | on: Quitting the arc server

Not a dumb question at all; there may well be something broken here.

It'll be a few hours before I can try running it, but one possibility: perhaps it will quit after serving one further request? Looking at the code (https://github.com/arclanguage/anarki/blob/3a07f946f9/lib/sr...) I think it's waiting on serve-socket before it gets around to checking quitsrv again. Can you try that if you haven't already?

-----

4 points by noobie 149 days ago | link

Thank you for your help!! Could you help me understand what you'd like me to do?

I'm not sure what you think I should try.

After looking up the definition of the 'until' macro, the line of code referenced seems to tell me: if quitsrv* is not nil, then continue to serve-socket, which looks to me, at a noobie's glance, as returning the function "accept-request-with-deadline", opening up threads to serve the request?

i.e., quitsrv* now returns t. According to this definition, doesn't that mean that serve-socket should stop?

And incidentally, when I run more defop macro calls, it returns the 'procedure' but (asv) doesn't work; none of the new page on localhost show up (instead it is "Unknown"). I'll look more into it but not really sure how to proceed after glancing at (def asv).

I've copied down the definitions for while and whilet from arc.arc but they don't seem helpful at first glance. Will look further into them if you think it would be useful.

Thank you!!

-----

4 points by akkartik 149 days ago | link

Not at all. I meant that if your server doesn't serve much traffic it'll spend much of its time inside serve-socket blocked on a new connection. It's only after serving a connection that it'll loop around to check quitsrv.

I just ran an experiment, and indeed the server stops after one more request:

    $ ./run-news
    initializing arc..
    ready to serve port 8080
    arc> (= quitsrv* t)
    ; now browse to localhost:8080; page served
    quit server ; printed by *serve*
    ; hit reload on localhost:8080; no response

-----

3 points by akkartik 157 days ago | link | parent | on: Yet another post regarding Arc & Heroku

I don't really know Heroku, sorry, but to answer your final question: It was a while ago, but I used to host an Arc webapp on a VPS behind Apache/Nginx.

-----

3 points by matthewwiese 156 days ago | link

Cool, thanks for the reply :) I've seen it discussed elsewhere that the way to have SSL (at least with the News example in the repository) is to run through Nginx.

Did that complicate your setup by much?

-----

5 points by shader 156 days ago | link

I've recently discovered the Caddy server (https://caddyserver.com/), which makes SSL and application proxy deployments super easy. Like, 2 lines of config:

  domain.com               #uses the domain to automatically set up SSL with Let's Encrypt
  proxy / localhost:8080   #redirect everything to Arc on 8080
I will say that Arc runs a bit resource intensive, and the slightly slow boot times mean you don't want it to have to re-launch because of infrequent requests. I don't know how well it would work on Heroku.

Also, some VPS services like vultr.com offer $5/mo nodes that have more resources than what you get from Heroku at $7/mo anyway.

-----

4 points by shader 156 days ago | link

I should mention that if what you want from Heroku is their deployment process, you can actually replicate some of it pretty easily with Caddy (though I have not done so yet myself; I plan to soon...)

Specifically, they have support for automatically fetching code from git and running a command in the repo, either periodically or triggered by a webhook: https://caddyserver.com/docs/http.git

That doesn't get you the app ecosystem that heroku offers, but you can get a lot of that pretty easily via docker and docker-compose now.

-----

More