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

Can one determine if an optional inline command argument has been provided #2163

Open
ToonTalk opened this issue Aug 2, 2018 · 7 comments
Open

Comments

@ToonTalk
Copy link

ToonTalk commented Aug 2, 2018

I tried this

image

but the = predicate reported false.

Generally is the following right?

image

Perhaps related to #1204

Generally I'm unclear about best practice regarding using inline commands versus c-shaped for command arguments

@bromagosa bromagosa reopened this Aug 2, 2018
@bromagosa
Copy link
Collaborator

Sorry, accidentally clicked on "Close issue".

I was about to write that there are different criteria for function comparison. Since what you're comparing are two lambdas, they'll always be different from each other even if their code content looks the same, as their context is necessarily different.

On the other hand, if you assigned a function to a variable and then compared it against itself, you'd get "true":

image

This also works for copies:

image

@Naharie
Copy link

Naharie commented Aug 2, 2018

@ToonTalk You can't check if a ring is empty in Snap!, but you can with javascript. Here's a helper block that does just that:
helper

@brianharvey
Copy link
Collaborator

About inline vs. C-shaped: We use inline in primitives, such as RUN, in which we expect the actual input expression to be a variable rather than a constant script. We use C-shaped in all other contexts, for which the actual input is likely to be a specific constant script.

In general, there is no way to compare two procedures for EQUAL?-ness. We follow Scheme in this; the idea is that two procedures might well be functionally equivalent even if their texts are different, e.g., if they have different formal parameters but are otherwise the same, or even if the texs are exactly the same, but they were defined in different environments and use a free variable. If you think of a procedure as representing a function, two procedures might have altogether different algorithms that produce the same result; my standard example is f(x)=2x+6; g(x)=2(x+3). So we can only realistically test for EQ?-ness.

On our short-term list is a way to get the text of a lambda expression, so you'll be able to test two texts for EQUAL?-ness, at your own risk with respect to defining environments.

@ToonTalk
Copy link
Author

ToonTalk commented Aug 3, 2018

Good explanations. Thanks all.

I see that if I use a c-shape for optional command arguments that an unspecified argument is 0. Is this something one can depend upon being true in future versions of Snap!?

After writing this I realised that better to use a type test:

image

@ToonTalk
Copy link
Author

ToonTalk commented Aug 3, 2018

By the way I see that if I change an argument from inline to c-shape then existing code still works just has redundant rings. But if I change a c-shape argument to inline the command is lost. Would it be wrong to ringify it?

@brianharvey
Copy link
Collaborator

Ringifying is probably the right thing.

0 for an empty script is definitely the wrong thing! I hereby declare that a bug.

@cycomachead
Copy link
Collaborator

There's a lot of edge cases around changing types.

Duplicate of #581
Relates to #843

I see that if I use a c-shape for optional command arguments that an unspecified argument is 0. Is this something one can depend upon being true in future versions of Snap!?

This feels like an artifact of JS type coercion. :( At least JS's type rules have a spec.
<heavy-snark>There's no spec for Snap! therefore you can rely on nothing. </heavy-snark>

I think inline rings are more like default values, unfortunately. It's worth mentioning that an empty command ring will pass the type test of is a command ? so if you wanted to use inline inputs, you'd likely need to check using JSFunction.

This is another use case for introspection!

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

5 participants