Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 14 14:50
    tddschn starred gilch/hissp
  • Aug 10 06:04
    makslevental starred gilch/hissp
  • Jul 29 23:18

    gilch on docs-pass

    (compare)

  • Jul 29 23:18

    gilch on master

    doc fix: keyword -> control word Fix indent Remove low-value parenthetical and 4 more (compare)

  • Jul 29 23:18
    gilch closed #163
  • Jul 29 23:18
    gilch edited #163
  • Jul 29 23:14
    gilch synchronize #163
  • Jul 29 23:13

    gilch on docs-pass

    Fix install URL Use better example Fix pip install from git repo … (compare)

  • Jul 29 23:06
    gilch synchronize #163
  • Jul 29 23:06

    gilch on docs-pass

    Fix pip install from git repo … (compare)

  • Jul 29 23:04
    gilch opened #163
  • Jul 29 23:03

    gilch on docs-pass

    doc fix: keyword -> control word Fix indent Remove low-value parenthetical and 3 more (compare)

  • Jul 16 04:06
    mathisto starred gilch/hissp
  • Jul 01 18:57
    Gwing97 starred gilch/hissp
  • Jul 01 08:12
    juanjosworkbox starred gilch/hissp
  • Jun 26 15:00
    LeaveNhA starred gilch/hissp
  • Jun 26 10:18
    fourpartswater starred gilch/hissp
  • Jun 20 02:48
    gilch closed #161
  • Jun 20 02:48
    gilch locked #161
  • Jun 19 12:49
    bhougland18 opened #161
Kyle I S Harrington
@kephale
one thing that i'm getting hung up on is going from tuples to s-expressions
I wanted something like an apply:
(defmacro apply (f : :* args)
    `(operator..add '(,f) ,@args))
and i've tried some variations on that, but the closest result gives me a tuple
gilch
@gilch
Python 2 had an apply, but it was deprecated in 2.3 after they added star unpacking, and was removed in Python 3.
def apply(callable, args=(), kwargs={}):
    return callable(*args, **kwargs)
That's a function, not a macro.
I'm not exactly sure what you're trying to do with that template. Maybe you could clarify with an example input and output?
Kyle I S Harrington
@kephale
(apply + '(1 2))
that is a pattern I use a lot (not just for math, but that is the easy example)
gilch
@gilch
So you want a macro to transform (apply + '(1 2)) into (+ 1 2)?
Kyle I S Harrington
@kephale
yeah
and evaluate it
i believe that will give coverage of all cases of map-reduce
gilch
@gilch
(defmacro apply (f xs)
  `(,f ,@(cadr xs)))
apply is normally a function as I demonstrated in the Python def above.
Macros get all of their arguments quoted. Because they run at compile time, their arguments haven't been evaluated yet.
So passing '(1 2) means it's quoted twice.
Kyle I S Harrington
@kephale
hmm ok
ah yeah that cadr fix does it
ok i'll do some comparisons with a python implementation as well
gilch
@gilch
So you have (quote '(1 2)) and only want the '(1 2).
If you had called it with (apply + (1 2)), then you wouldn't have to strip the quote.
Kyle I S Harrington
@kephale
yeah, i see, but i would get confused without the '(1 2)
gilch
@gilch
Yeah, apply is supposed to be a function, so it can get evaluated arguments.
Kyle I S Harrington
@kephale
:thumbsup:
thank you!
gilch
@gilch
You can certainly expand a macro to a function call though.
(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.