Show HN: Pith language. JavaScript with a little bit of Python syntax

https://gabrielsroka.github.io/webpages/pith.html
by gabrielsroka • 4 years ago
2 1 4 years ago

I've been writing a lot of JavaScript and Python lately. I like Python's syntax, so I created a language called Pith that's JS with some Python-like syntax (but without trailing colons).

It's not a full compiler. It really just does search-and-replace, but I find it fun and useful in spite of some sharp edges. I use it on my smartphone to write and run short programs.

Here's an example using the HN API (https://github.com/HackerNews/API):

  max = 6
  ids = await getApi('topstories')
  for id in ids.slice(0, max)
    getItem(id)
  
  async def getItem(id)
    const div = document.createElement('div')
    results.appendChild(div)
    div.style = 'padding-bottom: 1em;'
    item = await getApi('item/' + id)
    ? item.title, '|', item.score
    url = '//news.ycombinator.com/item?id='
    div.innerHTML = item.title.link(url + id)
  
  async def getApi(path)
    url = '//hacker-news.firebaseio.com/v0/'
    return getJson(url + path + '.json')

Related Stories

Loading related stories...

Source preview

gabrielsroka.github.io