Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Basic "with block" equivalent in Julia?

Tags:

julia

I know in various programming languages there is a block syntax to simplifies expressions that have too much references to the fields of an object

e.g. in VB one can use with block whith following description:

By using With...End With, you can perform a series of statements on a specified object without specifying the name of the object multiple times. Within a With statement block, you can specify a member of the object starting with a period, as if the With statement object preceded it.

I want to do something like this in Julia:

With theCustomer
    .Name = "Coho Vineyard"
    .URL = "http://www.cohovineyard.com/"
    .City = "Redmond"
End With

or maybe: @With data .a=.b+c*d

Is there a With block equivalent in Julia?

like image 597
Reza Afzalan Avatar asked Dec 04 '25 11:12

Reza Afzalan


1 Answers

There is not, but you can just create a variable with a short name instead. If you also want to limit the scope in the same way as above, you can do e.g.

let c = theCustomer
    c.Name = "Coho Vineyard"
    c.URL = "http://www.cohovineyard.com/"
    c.City = "Redmond"
end

Not much more verbose, and doesn't require special syntax.

like image 85
Toivo Henningsson Avatar answered Dec 07 '25 17:12

Toivo Henningsson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!