Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pretty #28

Merged
merged 3 commits into from
Mar 4, 2015
Merged

pretty #28

merged 3 commits into from
Mar 4, 2015

Conversation

turanct
Copy link
Contributor

@turanct turanct commented Mar 4, 2015

Use pretty() instead of show()

@mathiasverraes
Copy link
Owner

nice, maybe smt can be done about the duplication in pretty and dump

@turanct
Copy link
Contributor Author

turanct commented Mar 4, 2015

You mean like this? https://gist.github.com/turanct/ff3ef81861b8c8acf3b5

@mathiasverraes
Copy link
Owner

Yeah, except that we lack the possibility to make private functions. For
now we could call it _prettyList instead.
I did some experiments a while back with a node js style functional module
system, which would solve this problem neatly, but I haven't gotten round
to implementing it properly.


Mathias Verraes
Software Consultant
Value Object Comm.V http://value-object.com
Blog http://verraes.net/ - Email [email protected] - Twitter
http://twitter.com/mathiasverraes - LinkedIn
https://www.linkedin.com/in/mathiasverraes

On 4 March 2015 at 10:55, turanct [email protected] wrote:

You mean like this? https://gist.github.com/turanct/ff3ef81861b8c8acf3b5


Reply to this email directly or view it on GitHub
#28 (comment)
.

@turanct
Copy link
Contributor Author

turanct commented Mar 4, 2015

In some functional programming languages, you have to explicitly "export" functions from within a namespace/module... i find it elegant & clear, but i suppose it will be difficult to accomplish in php?

@mathiasverraes
Copy link
Owner

I think it's possible.

return module(@MyModule, [@somedependency], function($somedependency) {
$myprivatefn = ...
$mypublicfn = ...
$otherpublicfn = ...
return export([@mypublicfn=>$mypublicfn, @otherpublicfn =>
$otherpublicfn]);
});

The module function registers the exported functions somehow. It also finds
dependencies, injects them into the current module. Perhaps you can then
access them by calling $somedependency->functionname(), using __call
behind the scenes. We'd basically be abusing php's OO as dynamic
dependency mgmt.

A theoretically working example:

// foo.php
return module(@foo, [@list], function($lists) {
$halves = $lists->map(divide(__,2), __);
return export([@halves=>$halves]);
});

// bar.php
return module(@bar, [@foo], function($foo) {
print(pretty($foo->halves(l(1, 2, 3))));
});

We might even do the thing that node does, where each module has it's own
dependencies, so you can have multiple versions of dependencies in your
application.


Mathias Verraes
Software Consultant
Value Object Comm.V http://value-object.com
Blog http://verraes.net/ - Email [email protected] - Twitter
http://twitter.com/mathiasverraes - LinkedIn
https://www.linkedin.com/in/mathiasverraes

On 4 March 2015 at 14:24, turanct [email protected] wrote:

In some functional programming languages, you have to explicitly "export"
functions from within a namespace/module... i find it elegant & clear, but
i suppose it will be difficult to accomplish in php?


Reply to this email directly or view it on GitHub
#28 (comment)
.

@bar
Copy link

bar commented Mar 4, 2015

@mathiasverraes Please don't use my handle for your amusement :p

@turanct
Copy link
Contributor Author

turanct commented Mar 4, 2015

@mathiasverraes maybe more like this

return module(@foo, [@list->map], function($map) {
    $halves = $map(divide(__,2), __);
    return export([@halves=>$halves]);
});

where you only import the map function from the lists module

@mathiasverraes
Copy link
Owner

@bar Oops, apologies. I hope nobody is named @foo or @list :-)

@mathiasverraes
Copy link
Owner

@turanct looks great!

I suppose you mean [@list=>map] ? [@list->map] is not legal php.

You can alias functions too: [@a=>dupe, @b=>dupe], function($dupe1, $dupe2)

@bar
Copy link

bar commented Mar 4, 2015

@turanct
Copy link
Contributor Author

turanct commented Mar 4, 2015

@mathiasverraes yes, that was a typo 🐐

@turanct
Copy link
Contributor Author

turanct commented Mar 4, 2015

actually, there's a problem if you want to get two functions out of the same module that way...

[@list => map, @list => reduce] won't work

@mathiasverraes
Copy link
Owner

module(foo, [list=>[map, reduce], other=>[map]], function($map, $reduce, $aliasedOtherMap)

@turanct
Copy link
Contributor Author

turanct commented Mar 4, 2015

👍

can we create an issue for the module system? PR has been hijacked by this overly superb module system 🚀

@mathiasverraes
Copy link
Owner

No need to ask. This project prefers action over consensus!


Mathias Verraes
Software Consultant
Value Object Comm.V http://value-object.com
Blog http://verraes.net/ - Email [email protected] - Twitter
http://twitter.com/mathiasverraes - LinkedIn
https://www.linkedin.com/in/mathiasverraes

On 4 March 2015 at 20:30, turanct [email protected] wrote:

[image: 👍]

can we create an issue for the module system? PR has been hijacked by this
overly superb module system [image: 🚀]


Reply to this email directly or view it on GitHub
#28 (comment)
.

mathiasverraes added a commit that referenced this pull request Mar 4, 2015
@mathiasverraes mathiasverraes merged commit a5a4817 into mathiasverraes:omikron Mar 4, 2015
@turanct turanct mentioned this pull request Mar 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants