Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
gilch
@gilch
(defmacro apply* (f xs)
  `(apply ,f ,xs))
Assuming that Python definition.
Which you could write in Hissp as
(define apply
  (lambda (callable : args ()  kwargs {})
    (callable : :* args  :** kwargs)))
Or inline it like
Kyle I S Harrington
@kephale
i think that define is exactly what i was after!
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