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
gilch
@gilch
I figured out how to doctest the quickstart, and it's uncovered some issues so far. I should have that done in a day or two.
Assuming no more surprises pop up.
Kyle I S Harrington
@kephale
yeah like the clojure airity overloads, but it was more of a passing thought than a pressing need
Kyle I S Harrington
@kephale
the issue is just that the current pypi version isn't usable for code that works with the latest master
i'm certainly fine working on a couple of machines, but its harder to play around with ideas to scale up (not that I'm quite ready for that yet, but could be in a week or so)
gilch
@gilch
Python doesn't have arity overloads built in, but you could implement a dispatcher with a starargs and a cond on its length.
If it's a pattern you use a lot, it wouldn't be too difficult to implement it in terms of that using a macro.
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.