Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Mar 26 19:13
    evhub labeled #539
  • Mar 26 19:12
    evhub commented #538
  • Mar 26 19:11
    evhub unlabeled #538
  • Mar 26 13:56
    zhenyulin opened #539
  • Mar 26 13:53
    zhenyulin closed #538
  • Mar 26 13:21
    zhenyulin commented #538
  • Mar 26 13:18
    zhenyulin commented #538
  • Mar 26 12:45
    zhenyulin commented #538
  • Mar 26 12:43
    zhenyulin commented #538
  • Mar 26 00:28
    evhub unlabeled #513
  • Mar 26 00:28
    evhub labeled #513
  • Mar 26 00:27
    evhub unlabeled #537
  • Mar 26 00:27
    evhub labeled #513
  • Mar 26 00:27
    evhub labeled #513
  • Mar 26 00:26
    evhub labeled #537
  • Mar 26 00:26
    evhub labeled #538
  • Mar 26 00:26
    evhub labeled #538
  • Mar 26 00:22
    zhenyulin opened #538
  • Mar 10 23:19
    eindiran commented #537
  • Mar 09 18:41
    evhub labeled #537
Nicholas A. Del Grosso
@nickdelgrosso
*wordy
Actually, it's not true--Name: str actually becomes a None in coconut, while in Python it is "not defined".
Evan Hubinger
@evhub
@nickdelgrosso Name: str sets Name to None on --target universal since Python < 3.6 doesn't support the Name: str syntax. If you pass --target 3.6, on the other hand, then Name will stay undefined.
pavelbraginskiy
@pavelbraginskiy
@evhub Installing coconut[all] doesn't work
ERROR: Could not find a version that satisfies the requirement trollius>=2.2; extra == "all" (from coconut-develop[all]) (from versions: 2.1.post2)
ERROR: No matching distribution found for trollius>=2.2; extra == "all" (from coconut-develop[all])
Evan Hubinger
@evhub
@pavelbraginskiy Should be resolved with coconut-develop as of #515.
Thurston Sexton
@tbsexton

I think I misunderstand some of the match statement finer points. if I have some id like idx='a' defined, plus a list of tuples that have (idx,val) pairs, I cant use matching to return the value of the idx I want, right? i.e. an in statement is not part of the match syntax?

because

match (idx, val) in tuple_list:
    print(val)

is not working...I guess I would have to map a sub-match over all of the tuples? one that matches on (idx, val) and returns nothing if no match occurred?

Thurston Sexton
@tbsexton

if I was going to be cheeky about this problem, I would probably say

(tuple_list
 |>  dict
 |> .get(idx, default)
)

which would work by merit of key-value lookup being fast. is there a pattern-matching solution to matching a substructure within an iterable that doesn't rely on class promotion shennaigans?

Evan Hubinger
@evhub
@tbsexton If you want to do lookup in a list of tuples by only the first element of the tuple then you really should just convert it into a dictionary. You can still use match if you want, though—just do:
match {=idx: val, **_} in dict(tuple_list):
    print(val)
Thurston Sexton
@tbsexton
@evhub such an elegant syntax! I somehow glossed over the spot in the docs where the =<var> pattern syntax was mentioned. Actually since it can be so powerful (and some of us are learning to pattern-match in Coconut coming from Python) some more examples of basic pattern match workflows/use-cases would be pretty nice in the docs (the long list of possible syntax options is great but can be a bit hard to process while problem-solving).
e.g. I just saw this example of how F#'s pattern matching made for elegant fizz-buzz solution http://trelford.com/blog/post/FizzBuzz.aspx ...these kinds of "practical" examples might be super nice for coconut. almost like mini/advanced tutorial series for after the vector making one.
I'm definitely trying to keep track of simple elegant examples I come across while using so I can submit some eventually.
Thurston Sexton
@tbsexton

A couple follow up questions I ran into using my data structures....

  • the above works because dicts are technically un-sorted, so {=idx:val, **_} doesn't imply anything about the position of the idx key in the dict. what if I'm searching in an ordered set? e.g. searching for a sub-list within a list where that sublist starts with 0? Do I have to know where that sublist lies to make a valid pattern? The docs say the [] pattern keeps track of the size of the list explicitly as part of the match.

  • I ran into a problem where I had a list of functions (produced parametrically) and wanted to get back a list of results by mapping a value to all of the functions. See here for Haskell version: https://stackoverflow.com/questions/27080626/haskell-apply-single-value-to-a-list-of-functions

Thurston Sexton
@tbsexton
but I don't think the $ operator functions as an applicator here as it does in haskell. [(+)$(2), (*)$(2), (**)$(2)] |> map$(($)(4)) gives a typeerror, saying the first argument must be callable.
any shorthand/operator for x,f-> f$(x)? Or just "apply function" operator?
Evan Hubinger
@evhub
@tbsexton The tutorial has some match examples, but I agree that more in the docs would be nice. Definitely submit a PR if you have some that you think would be good! For matching sorted data structures, yes, it will match the order. And in Coconut, the $ operator is partial application, not function application. The function application operator in Coconut is <| (see https://coconut.readthedocs.io/en/master/DOCS.html#pipeline).
Alamar
@AlamarW
Hey, I'm new to coconut and I'm running into a problem
code def data():
with open('data_1') as data:
return [x for x in data]
oof hold on
```def data():
with open('data_1') as data:
return [x for x in data]
def data():
    with open('data_1') as data:
        return [x for x in data]
Anyway, so I'm trying to read from a txt file 'data_1' and am printing it with data |> print
but my response is just the <function data at 0x....>
Alamar
@AlamarW
Nevermind, I found a solution to the problem. Thanks for the help though!
studentiks
@studentiks
Evan, good day! Just installed with pip install coconut on Archlinux, got following error:
ImportError: Coconut requires pyparsing/cPyparsing version >= 2.4.0 and < 2.4.1; got Cython cPyparsing v2.4.5 (run 'pip install --upgrade cPyparsing' to fix)
Had to downgrade cParsing to 2.4.0 to overcome. Is this a bug or feature? Thank you!
pavelbraginskiy
@pavelbraginskiy
@studentiks deps got properly updated on develop but not yet on master. Try installing coconut-develop instead.
Evan Hubinger
@evhub
@studentiks Hmmm... when you pip install coconut it shouldn't be giving you an incompatible cPyparsing. That looks like a bug.
Yeah, I think I know what the problem is.
I'll fix it on develop and try to get a new release out soon.
Evan Hubinger
@evhub
Should be fixed on release now.
studentiks
@studentiks
@evhub Thank you!
Thurston Sexton
@tbsexton
@evhub trying to run a jupyter lab session with mypy enabled; per the docs I assumed the "best" way was
coconut --jupyter lab --mypy but jupyter throws an "unrecognized flag" error. Any way to run mypy checks in the notebook?
e.g. wrote this (bizzare) function for the fun of it:
def e_filt(
    e:     np.array, 
    thres: float
) -> () -> np.array = a -> a[e>thres]
it returns a filtering function, expecting an array and a float. but passing two ints seems to not fail:
>>> e_filt(1, 1)
<function __main__.e_filt.<locals>.<lambda>(a)>
Was hoping mypy would throw an error
Thurston Sexton
@tbsexton
Also tried plain (non-numpy types), and ndarray/float64 types...still no errors
def e_filt(
#     e:     np.ndarray[np.float64],
#     thres: np.float64
    e: float[],
    thres: float,

# ) -> np.ndarray[np.float64] -> np.ndarray[np.float64] = 
) -> float[] -> float[] = 
    a -> a[e>thres]
Evan Hubinger
@evhub
@tbsexton If you want to get Mypy to run in Jupyter, you're going to have to do something on the Jupyter side to make that happen. coconut --jupyter lab --mypy won't work since Coconut just passes all the arguments after --jupyter to the jupyter command. Possibly you could use a cell magic like this or this (the Coconut kernel should support magics)—if you try that let me know how that goes. Possibly it might make sense to integrate a magic like that directly into Coconut—you should raise an issue for getting Mypy in Jupyter and I'll see if I can look into it at some point.
Elliott Indiran
@eindiran
This language isn't super serious but some folks here might find it interesting: http://pyos.github.io/dg/
Haskell-like syntax for Python (but none of the type system, lol)
Jacob Tan
@2jacobtan
lol that was funny
Jay Kint
@icosahedron
I don't suppose there is a coconut flavored wrapping for pandas/numpy, is there?
I know very little of the language, just learning, and wanted to do something with data, but I don't want to shoehorn those libraries in to coconut's functional syntax if there's something better available.
Evan Hubinger
@evhub
@icosahedron In my experience, Coconut works great with Numpy right out of the box. Numpy benefits a lot imo from pipes and partial application in particular—and also Coconut's fmap function is specifically built to play nicely with Numpy arrays.
Jay Kint
@icosahedron
@evhub Thanks!
Thurston Sexton
@tbsexton
@icosahedron I can second that, with respect to pandas. I pretty much exclusively write my pandas analysis pipelines in coconut now...it honestly mirrors best practices/piping naturally, anyway
much cleaner and easy to read, and to refactor... no more jupyter NBs filled with temporary dataframes performing what should have been a reproducible transformation
@evhub more of a brainstorming idea than a suggestion, but would there be any benefit to cross-compatibility with the pyrsistent/pyrthon effort?
Evan Hubinger
@evhub
@tbsexton What sort of cross-compatibility with pyrsistent would you want? You can already use pyrsistent data types in coconut. If you want coconut built-ins to play more nicely with pyrsistent data types, that should be possible. Special syntax for pyrsistent is a bit more questionable, but maybe.