Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 05:23
    gilch updated the wiki
  • 05:19
    gilch updated the wiki
  • 04:51
    gilch updated the wiki
  • 04:38
    gilch updated the wiki
  • 04:27
    gilch updated the wiki
  • May 14 20:33
    gilch commented #154
  • May 14 20:25
    gilch commented #157
  • May 14 20:21

    gilch on doc-pass2

    (compare)

  • May 14 20:21

    gilch on master

    Add docstrings for new bundled … Rename module literals handles Fix ensure and 22 more (compare)

  • May 14 20:21
    gilch closed #158
  • May 14 20:21
    gilch commented #158
  • May 14 20:20
    gilch commented #158
  • May 14 20:20
    codecov[bot] commented #158
  • May 14 20:20
    gilch commented #158
  • May 14 20:19
    gilch synchronize #158
  • May 14 20:19

    gilch on doc-pass2

    print_exc before interact Style Guide corrections Add slicing tutorial and 1 more (compare)

  • May 14 18:59
    gilch commented #158
  • May 14 18:58
    gilch synchronize #158
  • May 14 18:58

    gilch on doc-pass2

    Move no-file compilations to tr… Rework Ensue print_exc before interact and 3 more (compare)

  • May 14 18:55
    gilch opened #158
gilch
@gilch
(defmacro apply (f xs)
  `((lambda ($#f $#xs)
      ($#f : :* $#xs))
    ,f ,xs))
There's really no difference between s-expressions and tuples in Lissp like there is in Hy. A quoted s-expression compiles to a tuple, and s-expressions read as Hissp tuples.
Whereas Hy has a separate HyExpression type.
gilch
@gilch
If I recall, Clojure's apply was a bit different.
Kyle I S Harrington
@kephale
thats what I thought (yeah the HyExpressions really threw me off). I kept ending up with results that were tuples, but I think I was missing a deeper concept
but Clojure's apply can work the same way at least
gilch
@gilch
def apply(f, *args):
    *args, star = args
    return f(*args, *star)
That one would work more like Clojure.
(define apply
  (lambda (f : :* args)
    (f : :* (getitem args (slice -1))
       :* (getitem args -1))))
Should be the equivalent of that Python.
gilch
@gilch
Maybe "quoted twice" is the wrong way to say it. The macro gets the Hissp code: ('quote', (1, 2)) and you wanted the (1, 2).
There was never a second 'quote' string in that process.
When I said that macros get their arguments quoted, I meant that they get the unevaluated Hissp, not that it's wrapped in quote forms.
I didn't really get any work done on Hissp today, but I can probably still get that PyPI release done in a week. Probably.
gilch
@gilch
I think I had also worded it as macros getting quoted arguments in the docs. I should reword that.
gilch
@gilch
You pretty much don't need apply given the star unpacking. Maybe if you needed it for a higher order function. But then something like %#(%1 : :* %2) should work.
Or %#(+ : :* %) if the function is fixed.
Kyle I S Harrington
@kephale
ok, I'm still understanding the ways of benefiting from Hissp's lambda implementation. that said i think i prefer using apply over directly using the reader macro with star unpacking, just for readability
gilch
@gilch
Given itertools.starmap and star unpacking, I don't recall ever missing apply in Python.
gilch
@gilch
Another advantage of star unpacking is that you can do it more than once in the same call, like (foo bar : :* spam :? baz :* eggs).
Kyle I S Harrington
@kephale
how do you make a list of strings? ["a","b"] doesn't work, although [1,2] does
gilch
@gilch
['a','b']
Collection atoms are injections, so they use Python syntax.
There are a lot of examples in the quick start: https://hissp.readthedocs.io/en/latest/lissp_quickstart.html
See the ;;;; COLLECTIONS section.
[\"a\",\"b\"] also works, but single quotes are easier.
gilch
@gilch
(list '(a b)) would also work, but beware of munging when using symbols as strings this way.
You might expect (list '("a" "b")) to also work, but that has to compile the quotes in to distinguish them from identifiers, resulting in ["('a')", "('b')"].
The right way to do that is (list `(,"a" ,"b")).
gilch
@gilch
Unlike the collection atoms, you can interpolate runtime values this way.
If you're doing anything complicated, like nesting these, or using them in macro templates, the overhead of managing the unquotes and the extra set of parentheses can make this difficult.
In that case, I'd recommend using helper functions.
gilch
@gilch
If you like Python's default collections, that would mean the entuple, endict and enlist helpers demonstrated in the quick start.
You could also define an enset in a very similar way to enlist.
If you'd rather have collections that work more like Clojure, I'd recommend installing pyrsistent and using their helpers.
gilch
@gilch
They implement the appropriate collection protocols, so they mostly just work with other Python libraries, and in case they don't, you can thaw.
Kyle I S Harrington
@kephale
one thing i keep seeing over and over, i think it is coming from using nested macros "SyntaxError: Bad space: '\t'"
a minimal example is:
this throws the error
(.upper (let (mystr "asdf")
          (operator..add mystr "ghj")))
this doesnt:
(.upper (let (mystr "asdf") (operator..add mystr "ghj")))
gilch
@gilch
Tab characters are not allowed for indentation in Lissp. Use spaces.
Kyle I S Harrington
@kephale
ah ok, i was just using the default behavior of emacs and dont really care about the difference
great that it is an easy fix
gilch
@gilch
I suppose I could make that error message clearer.
Tabs are allowed in strings, they just aren't whitespace.
Kyle I S Harrington
@kephale
is there a technical reason?
gilch
@gilch
Standard tab stops are technically supposed to be equivalent to 8 spaces, when used as indentation. But you more often see them set to 2 or 4, and 1 or 3 is not that rare either. Because indentation is so important for legibility in Lisp, and for Parinfer to work, bad tabstop settings can cause a lot of issues.
Kyle I S Harrington
@kephale
i see
so legibility/parainfer, and not something like reader macro clashes or things along those lines