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

Enhancement: add "|none" to each named argument of each code section method #78

Open
dumblob opened this issue Sep 29, 2015 · 6 comments

Comments

@dumblob
Copy link

dumblob commented Sep 29, 2015

Currently it's impossible to simply express, that one doesn't want to mention an attribute in some cases, but does want to in other cases anchor(_class=%c ? c : none){ .... This might be easily achieved by enhancing the interface of each code section method argument with |none with the following semantics:

anchor(href=none){} -> <a></a>
anchor(href=5){} -> <a href="5"></a>

none could be also used with the same semantics for return values of code section methods:

anchor { "" } -> <a></a>
anchor {} -> anchor { none } ->

But this use for whole tags seems slightly odd, even though it's handy.

@Night-walker
Copy link
Collaborator

You proposal is based on an invalid assumption. You can't write c? a : b if the types of a and b don't match.

@Night-walker
Copy link
Collaborator

It would make the prototypes too complicated. Try to use tuples to make attribute lists.

@dumblob
Copy link
Author

dumblob commented Oct 1, 2015

Try to use tuples to make attribute lists.

dao -e 'load web.html import html; fragment { x = 5 == 5 ? (@T)(href="yes",_class="sth") : (@T)(href="no",); anchor(x, ...) { "A" } }

Currently impossible/difficult due to bug daokoder/dao#507 .

@dumblob
Copy link
Author

dumblob commented Oct 5, 2015

Bug daokoder/dao#507 has been fixed, but the example doesn't work anyway. What did you mean by Try to use tuples to make attribute lists.?

@dumblob
Copy link
Author

dumblob commented Oct 5, 2015

routine r(...: tuple<enum<x>, int>|tuple<enum<y>, string> as args) { io.writeln(args) }
t = 0 == 0 ? (($x,9),) : (($y, "c"), ($x,3))
r(t, ...)

This also doesn't work (of course, because tuple types are not matching), even though it can be solved pretty easily with casting to tuple<...>. But the issue with this is, that it's really cumbersome and unreadable.

@Night-walker
Copy link
Collaborator

What did you mean by Try to use tuples to make attribute lists.?

Only that you can attempt to construct tuples of arguments based on your conditions and then pass them to tag functions.

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

No branches or pull requests

2 participants