Where is more newbie forum for e-z syntax Qs?

Sorry for a beginner question. I cannot find a forum where I can ask very beginner-type syntax questions. I will ask it here for now. I used the recommended textbooks, by Evan, by Pawan Poudel, but I puzzle over them for days, stuck, since October.

My question today is, based on what I have learned, the below code I wrote should not run, but it does!

  1. “foobar” can be anything. But the code breaks if I remove it. It seems both meaningless and vital. What role is “foobar” playing?
  2. What do the first two words of my program below mean, what are they called, are they strings? variables? function and argument? the two-word syntax of ‘view model’ tells me there is a function called VIEW that takes one argument, MODEL. But that is wrong. Stuck.

` view model =
div []
[ article [] [ text “Yayyyy” ]
, button [] []
]

main =
    view "foobar"

Sorry, I know this is not the right place for this question.

Please ignore the above. I found two better places for it. Both perfect:

  1. Elm Reddit
  2. Slack Elm #beginner

Let me answer in reverse order.

Your interpretation is correct: view is a function taking one argument; that argument is called model. Why do you think it’s not?

Your function view does not use its argument in any way (model does not appear to the right of =). Hence, your argument can be any value, but it has to be a value, it cannot simply leave it off.

If you want view not to require an argument, remove model in its definition and call it without "foobar".

no need to apologize, you’re asking in the right place! I can also recommend #beginners on Slack (which it seems like you’ve already found.)

You’ve actually mostly got it already: you have function called view that takes an argument called model. That function, right now, is taking "foobar" but ignoring it as it’s not used anywhere in the body of the function. If you want to remove "foobar" you’ll need to not take the argument.

In Elm, view model = ... is the equivalent of JavaScript’s function view(model) { ... }. It seems like you want the equivalent of function view() { ... }, which would look like this:

view =
    div []
        [ article [] [ text "Yayyyy" ]
        , button [] []
        ]

and you would call it like this:

main =
    view

Just to reinforce: welcome to the Elm community! I hope you enjoy yourself here! Please feel free to ask questions wherever you feel comfortable. :smile:

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.