Are there line breaks in Elm? - elm

I'm calling a function in Elm and some of the variable names I'm passing as parameters are kind of long, so I'd rather not put it all on 1 line. But I'm having trouble figuring out how to do that.
Normally, from experience with other languages, I'd imagine it might look something like this:
result =
Dict.foldr \
dataTransformationFunction \
0 \
initialStateDict
That obviously didn't work though. I tried using |> and <|, but I couldnt get anything using those to compile (since 0 and the other parameters arent functions that takes arguments, I couldn't pipe).
Am I doing something wrong here, or is there no way to add a line break in Elm code?

Looks like I forgot to try the simplest option; you don't need a special character/operator to do a line break if none of your parameters require any (more) arguments.
This is perfectly legal:
result =
Dict.foldr
(myFunction)
0
initialStateDict

Related

Evaluating Variables in Load Script

Is there any reason that this syntax shouldn't work in Qlikview load script??
Let v_myNumber = year(today());
Let v_myString = '2017-08';
If left($(v_myString),4) = text($(v_myNumber)) Then
'do something
Else
'do something else
End If;
I've tried both ways where I convert variable string to number and evaluate against the number variable directly and this way. They won't evaluate to equivalence when they should..
Left function is expecting a string as is getting something else as a parameter. As you are currently doing, the function will be called as Left(2017-08, 4) which is unhandle by QlikView.
If you use Left('$(v_myString)',4), it will evaluate as Left('2017-08', 4) as work as expected. Just adding quotes around the variable it should work.
Although QlikView calls them variables, they should really be seen as "stuff to replaced (at sometimes evaluated) at runtime", which is slightly different from a standard "variable" behaviour.
Dollar sign expansion is a big subject, but in short:
if you are setting a variable - no need for $().
if you are using a variable - you can use $(). depends on its context.
if you are using a variable that needs to be evaluated - you have to use $().
for example in a load script: let var1 = 'if(a=1,1,2)' - here later on the script you will probably want to use this variable as $(var1) so it will be evaluated on the fly...
I hope its a little more clear now. variable can be used in many ways at even can take parameters!
for example:
var2 = $1*$2
and then you can use like this: $(var2(2,3)) which will yield 6
For further exploration of this, I would suggest reading this

Declare a variable

I didn't touch Prolog since high-school, and even though I've tried to find the info, it didn't help. Below is the example that has to illustrate my problem:
%% everybody():- [dana, cody, bess, abby].
%% Everybody = [dana, cody, bess, abby].
likes(dana, cody).
hates(bess, dana).
hates(cody, abby).
hates(X, Y):- \+ likes(X, Y).
likes_somebody(_, []):- fail.
likes_somebody(X, [girl | others]):-
likes(X, girl) ; likes_somebody(X, others).
likes_everybody(_, []):- true.
likes_everybody(X, [girl | others]):-
likes(X, girl) , likes_everybody(X, others).
maplist(likes_somebody, [dana, cody, bess, abby], [dana, cody, bess, abby]).
How do I declare everybody to just be the list of girls? The commented lines are those which I've tried, but I've got bizarre error messages back.
This is the tutorial I followed more or less so far. I'm using GProlog, if it makes any difference. Sorry for such a basic question. GProlog's manual doesn't deal with language syntax, but I've certainly looked there. As an aside, I would be grateful for information on where to look for language documentation (as opposed to implementation documentation).
Every variable in Prolog must begin with an uppercase letter. So for starters, you want Everybody, not everybody.
Second problem, variables in Prolog are not assignables. So probably what you want to do is make a fact and use that instead:
everybody([dana, cody, bess, abby]).
Your bottom line of code is actually a fact definition and will attempt to overwrite maplist/3. What you probably want to do is put everything above that line into a file (say, called likes.pl) and then consult it ([likes].). Then you can run a query like this:
?- everybody(Everybody), maplist(likes_somebody, Everybody, Everybody).
This won't work, because likes_somebody/2 processes a list in the second argument. The predicate you have for likes_somebody/2 could be written:
likes_somebody(_, []).
but still won't mean much. It simply unifies anything with the empty list:
?- likes_somebody(chicken_tacos, []).
true.
You really need a predicate to tell you if someone is a girl, like this:
girl(dana).
girl(cody).
girl(bess).
girl(abby).
Then you could do what I think you're trying to do, which is something closer to this:
likes_somebody(X) :- girl(X).
Then the maplist construction would work like this:
everybody(Everybody), maplist(likes_somebody, Everybody).
Which would simply return true. You could simplify and eliminate everybody/1 by instead using findall(Girl, girl(X), Everybody) but it's getting weird.
You're trying to do list processing with likes_everybody/2, but it's broken because girl is literally girl, not a variable, and others is literally others, not a list of some kind that could be the tail of another list.
I think you still have some old ideas you need to cleanse. Read some more, write some more, and your code will start to make a lot more sense.

Passing a block to .try()

This question is about using the .try() method in rails 3 (& a bit about best practice in testing for nil also)
If I have a db object that may or may not be nil, and it has a field which is eg a delimited string, separated by commas and an optional semi-colon, and I want to see if this string contains a particular sub-string, then I might do this:
user_page = UserPage.find(id)
if user_page != nil
result = user_page.pagelist.gsub('\;', ',').split(",").include?(sub)
end
So, eg user_page.pagelist == "item_a,item_b;item_c"
I want to re-write this using .try, but cannot find a way of applying the stuff after pagelist
So I have tried passing a block (from this link http://apidock.com/rails/Object/try)
user_page.try(:pagelist) {|t| t.gsub('\;', ',').split(",").include?(sub)}
However, the block is simply ignored and the returned result is simply pagelist
I have tried other combinations of trying to apply the gsub etc part, but to no avail
How can I apply other methods to the method being 'tried'?
(I dont even know how to phrase the question in an intelligible way!)
I think you're probably coming at this wrong - the quick solution should be to add a method to your model:
def formatted_pagelist
(pagelist || "").split(/[;,]/)
end
Then you can use it where ever:
user_page.formatted_pagelist.include? sub
Strictly speaking, I'd say this goes into a decorator. If you're not using a decorator pattern in your app (look into draper!), then a model method should work fine.

"Expected unqualified-id" in #define statement

I'm trying to simplify my code by using #define statements. This is because it contains a lot of repetitive "chunks" of code that cannot be repeated using the obvious alternative, functions, because in these chunks, variables need to be declared like you'd do in a #define statement, e.g. #define dostuff(name) int name##Variable;.
Code
#define createBody(name,type,xpos,ypos,userData,width,height) b2BodyDef name##BodyDef;\
name##BodyDef.type = type==#"dynamic"?b2_dynamicBody:b2_staticBody;\
name##BodyDef.position.Set(xpos,ypos);\
name##BodyDef.userData = userData;\
name=world->CreateBody(&name##BodyDef);\
b2PolygonShape name##shape;\
name##shape.SetAsBox(width/ptm_ratio/2,height/ptm_ratio/2);
... and applying that in the following:
createBody(block, #"dynamic", winSize.width*5/6/ptm_ratio, winSize.height*1/6/ptm_ratio, ((__bridge void*)blockspr), blockspr.contentSize.width, blockspr.contentSize.height)
// error appears there: ^
Now my point is that everything's working great, no errors, except a single one that's freaking me out:
Expected unqualified-id
which points at the first bracket in ((__bridge ..., as indicated. (That argument gets passed via the userData argument to createBody.)
I know this code is nowhere near simple, but since everything else is working, I believe that an answer must exist.
This is my first question on SO, so if there's anything unclear or insufficient, please let me know!
I'm trying to simplify my code by using #define statements.
This sounds an alarm in my mind.
Break this down into functions. You said you can't. I say you can.
Notice that your macro here:
createBody(name,type,xpos,ypos,userData,width,height);
It has exactly the same syntax as a C function. So you've already created a function, you only declared it as a macro. There's no reason why you couldn't rewrite it as a function (C or Objective-C doesn't matter). You do not need to give each body its own name, instead you could store them in a dictionary (careful though because Box2D takes ownership of the bodies).

obfuscated way to get "0" in a tcl function, cross platform?

I haven't used tcl before and just need to do one trick, I can do it trivially in something like bash but I need it to work cross-platform (e.g. tcl in cygwin on windows).
Can someone suggest a short (5-10) obfuscated function that just returns 0 after taking two string args? It just can't do something like run shell commands that won't work under Mac/Cygwin.
fwiw, why do this: buying some time in writing a test- the thing generating one of the files is broken but I can't change it, making a hack in the TCL test script until I make extensive changes to use a different 'test core' that isn't broken. For now just declare the first file as 'good' if it exists.
I don't understand the requirement for obfuscation, but the simplest way to create a command that takes two arguments and returns 0 is this:
proc theCommandName {firstArgument secondArgument} {
return 0
}
There are all sorts of ways of making things obscure (e.g., a regular expression that doesn't actually match anything, a complicated expression) but as I said before, I don't understand the requirement in that area; I always try to make my code be the simplest thing that could possibly work…