#86Allow simplifying function expressions when there are used as the last argument in a function call

  • avatar~lucsoftcommented · 2 years ago
    Author

    User Story

    Frontend Developer

    As a Frontend developer, I'm used to composing multiple function together to create inherently a tree structure of dom nodes, as this is most of the code i produce it should be as syntax less as possible and specialities should stand out as i care more about these.

    fn HomePage() {
         var currentUser = await query.getActiveUser()
         val blogs = await query.getCurrentBlogs()
    
         LimitedContentWidth {
              NavigationBar {
                   Logo
                   Label("My Personal Blog 🤩")
                   Spacer
                   Link("GitHub", "https://github.com/")
                   Link("Discord", "https://discord.gg/")
                   if currentUser {
                        ProfilePicture(currentUser)
                   } else {
                        LoginButton
                   }
              }
              Section {
                   Label("Latest News")
                   List(blogs) { blog ->
                        Card {
                             Label(blog.title)
                             Flex {
                                  Spacer
                                  Label(blog.blogUrl)
                             }
                        }
                        .backgroundImage(blog.backgroundImage)
                   }
              }
         }
    }
    

    Milestone: 0.3.0.

  • avatar~lucsoft changed the status to Todo · 2 years ago
  • avatar~lino-levancommented · 2 years ago

    I'm still of the idea that this should be done with macros instead of like the way swift does it (which is what I assume your syntax is inspired by). Interesting proposal though, we'll see what @paperdave thinks.

  • avatar~clovercommented · 2 years ago
    Owner

    i have no idea what i am looking at or what this proposal is.

    LimitedContentWidth { what is this syntax structure? a struct literal has fields.

    List(blogs) { blog -> what is this?

    can you give a full example of what you want to specifically change in the language, otherwise i will close this.

  • avatar~lucsoftcommented · 2 years ago
    Author

    Imagine a function definition of

    fn LimitedContentWidth(block: () -> void) { [...] }

    Now you could write it as

    LimitedContentWidth(() -> {

    })

    But my proposal states that it should be possible to simplify these callbacks to

    LimitedContentWidth {

    }

    Still exactly the same code

  • avatar~clovercommented · 2 years ago
    Owner

    ah, this cannot work without a lot of changes because changing call(fn { ... }) into call { ... } would make it parse as a struct initialization.