Arc Forumnew | comments | leaders | submitlogin
Can anybody explain this in news.arc code?
1 point by rick_2047 5416 days ago | 5 comments
I have been trying to understand the news.arc code, I did a few edits and was trying to make the ask page as there is on HN. To make that I will have to have a list like stories* which is generated in the code here.

  (= stories*  (rev (merge (compare < !id) items!story items!poll)) comments* (rev items!comment))
I have three questions,

1) What does the asterisk stand for?

2) What is items and where does it come from?

3) What does the bang(!) operator stand for?



2 points by shader 5416 days ago | link

1) The asterisk is a naming convention for global variables.

2) If you look at the block surrounding the code you put up:

  (with (items (table)
         ids (sort > (map int (dir storydir*))))
    (if ids (= maxid* (car ids)))
    (noisy-each 100 id (firstn initload* ids)
      (let i (load-item id)
        (push i (items i!type))))
    (= stories* (rev (merge (compare < !id) items!story items!poll))
       comments* (rev items!comment))
    (hook 'initload items))
you'll see that items is a table, as declared by "(with (items (table)...", used to store items loaded from file. The definition of an item is found closer to the top in the "(deftem item" block

3) The bang operater a!b is equivalent to (a 'b) and is used as a shorthand for table lookup.

-----

1 point by rick_2047 5416 days ago | link

3) The bang operater a!b is equivalent to (a 'b) and is used as a shorthand for table lookup.

But there are many instances it has been used on single symbols like !id. How do I interpret that?

EDIT: I found out! !id is only used with compare, so this is applied to the body like (items!story items!poll). But my problem still exits, how do I find out the story is a local post or a one with url.

-----

2 points by rocketnia 5414 days ago | link

But my problem still exits, how do I find out the story is a local post or a one with url.

You mean whether it's a topic with a URL and no text or a topic with text and no URL, right? Hmm, it looks like 'item-page is responsible for displaying the /item?id=... URL, and that calls 'display-item-text to display the textual content of the post. The implementation of 'display-item-text looks like this:

  (def display-item-text (s user)
    (when (and (cansee user s) 
               (in s!type 'story 'poll)
               (blank s!url) 
               (~blank s!text))
      (spacerow 2)
      (row "" s!text)))
So it seems stories have both URLs and text internally, but the text is never displayed unless (blank s!url). That's probably the test you're looking for.

In any case, welcome to Arc Forum! ^_^

-----

2 points by evanrmurphy 5415 days ago | link

> But there are many instances it has been used on single symbols like !id. How do I interpret that?

a!b and (!b a) are equivalent:

  arc> (= a (table))
  #hash()
  arc>(= a!b 42)
  42
  arc> a!b
  42
  arc> (!b a)
  42
  arc> (is a!b (!b a))
  t
Hope this helps.

-----

2 points by rick_2047 5415 days ago | link

Ya I learned that, but that still doesn't solve the problem I have. Please see the edit.

-----