Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Pith language. JavaScript with a little bit of Python syntax (gabrielsroka.github.io)
2 points by gabrielsroka on Sept 1, 2022 | hide | past | favorite | 1 comment
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')





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: