Hacker News new | ask | show | jobs
by gabrielsroka 2042 days ago
I tried a few (not all) of the examples with plain old Python (granted, these are multi-liners, not one-liners, but I think they're easier to read). I'm not sure I see the advantange of curly braces.

  # --- Example 1
  
  # pwk
  pwk 'if "braces"=="bad": { print("Be gone!"); exit(99) } else: { print("Howdy!") }'
  
  # vs
  
  # python
  python -c 'if "braces"=="bad": print("Be gone!"); exit(99)
  else: print("Howdy!")'
  
  
  # --- Example 2
  
  pwk 'def s2i(s): { return int(s) } print(s2i("41")+1)'
  
  python -c 'def s2i(s): return int(s)
  print(s2i("41")+1)'
  
  
  # --- Example 3
  
  ls / | pwk 'for s in sys.stdin: try: { print(os.listdir("/"+s.strip())) } except: pass'
  
  ls / | python -c 'import sys, os
  for s in sys.stdin:
   try: print(os.listdir("/"+s.strip()))
   except: pass'
2 comments

The advantage is the one-line versions can be easily written within the Terminal.
You're braver than I -- whenever a shell/terminal indicates to me it expects multiline now, I press, in that order, Ctrl+C, Ctrl+D, Ctrl+Z, and Ctrl+Alt+Del.