Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Sequential With

From Daniel Lichtblau's comment there is a new undocumented syntax for With introduced sometime after version 10.1 that allows:

With[{a = 0}, {a = a + 1}, {a = a + 1}, a]
2

Delayed With, Block, and Module

These scoping constructs support the use of := in definitions which allows one to handle unevaluated expressions.

With[{x := 2 + 2}, Trace[x]]
Block[{x := 2 + 2}, Trace[x]]
Module[{x := 2 + 2}, Trace[x]]
{2 + 2, 4}
{x, 2 + 2, 4}
{x$6064, 2 + 2, 4}

###Examples:

  • I find this most useful in With since it inserts definitions into held expressions.
    I commonly use this for in-place modification of DownValues:

      a[1] = Pi;
      a[2] = E;
    
      With[{dv := DownValues[a]},  dv = dv /. {1 -> 3};]
    
       a[3]   (*  out=  π  *)
    
  • Kuba finds it very useful for writing readable controllers definitions.

E.g.

    asso = <|"nested" -> <|"key" -> <|
        "spec" -> <|"a" -> 1, "b" ->  0|>
    |>|>|>;

    With[{
      a := asso["nested", "key", "spec", "a"],
      b := asso["nested", "key", "spec", "b"]
      },
     DynamicModule[{},
       Column@{
        Slider@Dynamic[a],
        Slider[Dynamic[b, {Automatic, (a = b^2) &}]],
        Dynamic@asso
        }
     ]
 
    ]

The earliest Stack Exchange usage of this that I can find is a post by Szabolcsa post by Szabolcs.

I implemented a similar syntax in my listWith function which is itself an extension of With.


Sequential With

From Daniel Lichtblau's comment there is a new undocumented syntax for With introduced sometime after version 10.1 that allows:

With[{a = 0}, {a = a + 1}, {a = a + 1}, a]
2

Delayed With, Block, and Module

These scoping constructs support the use of := in definitions which allows one to handle unevaluated expressions.

With[{x := 2 + 2}, Trace[x]]
Block[{x := 2 + 2}, Trace[x]]
Module[{x := 2 + 2}, Trace[x]]
{2 + 2, 4}
{x, 2 + 2, 4}
{x$6064, 2 + 2, 4}

###Examples:

  • I find this most useful in With since it inserts definitions into held expressions.
    I commonly use this for in-place modification of DownValues:

      a[1] = Pi;
      a[2] = E;
    
      With[{dv := DownValues[a]},  dv = dv /. {1 -> 3};]
    
       a[3]   (*  out=  π  *)
    
  • Kuba finds it very useful for writing readable controllers definitions.

E.g.

    asso = <|"nested" -> <|"key" -> <|
        "spec" -> <|"a" -> 1, "b" ->  0|>
    |>|>|>;

    With[{
      a := asso["nested", "key", "spec", "a"],
      b := asso["nested", "key", "spec", "b"]
      },
     DynamicModule[{},
       Column@{
        Slider@Dynamic[a],
        Slider[Dynamic[b, {Automatic, (a = b^2) &}]],
        Dynamic@asso
        }
     ]
 
    ]

The earliest Stack Exchange usage of this that I can find is a post by Szabolcs.

I implemented a similar syntax in my listWith function which is itself an extension of With.


Sequential With

From Daniel Lichtblau's comment there is a new undocumented syntax for With introduced sometime after version 10.1 that allows:

With[{a = 0}, {a = a + 1}, {a = a + 1}, a]
2

Delayed With, Block, and Module

These scoping constructs support the use of := in definitions which allows one to handle unevaluated expressions.

With[{x := 2 + 2}, Trace[x]]
Block[{x := 2 + 2}, Trace[x]]
Module[{x := 2 + 2}, Trace[x]]
{2 + 2, 4}
{x, 2 + 2, 4}
{x$6064, 2 + 2, 4}

###Examples:

  • I find this most useful in With since it inserts definitions into held expressions.
    I commonly use this for in-place modification of DownValues:

      a[1] = Pi;
      a[2] = E;
    
      With[{dv := DownValues[a]},  dv = dv /. {1 -> 3};]
    
       a[3]   (*  out=  π  *)
    
  • Kuba finds it very useful for writing readable controllers definitions.

E.g.

    asso = <|"nested" -> <|"key" -> <|
        "spec" -> <|"a" -> 1, "b" ->  0|>
    |>|>|>;

    With[{
      a := asso["nested", "key", "spec", "a"],
      b := asso["nested", "key", "spec", "b"]
      },
     DynamicModule[{},
       Column@{
        Slider@Dynamic[a],
        Slider[Dynamic[b, {Automatic, (a = b^2) &}]],
        Dynamic@asso
        }
     ]
 
    ]

The earliest Stack Exchange usage of this that I can find is a post by Szabolcs.

I implemented a similar syntax in my listWith function which is itself an extension of With.

replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

Sequential With

From Daniel Lichtblau's commentDaniel Lichtblau's comment there is a new undocumented syntax for With introduced sometime after version 10.1 that allows:

With[{a = 0}, {a = a + 1}, {a = a + 1}, a]
2

Delayed With, Block, and Module

These scoping constructs support the use of := in definitions which allows one to handle unevaluated expressions.

With[{x := 2 + 2}, Trace[x]]
Block[{x := 2 + 2}, Trace[x]]
Module[{x := 2 + 2}, Trace[x]]
{2 + 2, 4}
{x, 2 + 2, 4}
{x$6064, 2 + 2, 4}

###Examples:

  • I find this most useful in With since it inserts definitions into held expressions.
    I commonly use this for in-place modification of DownValues:

      a[1] = Pi;
      a[2] = E;
    
      With[{dv := DownValues[a]},  dv = dv /. {1 -> 3};]
    
       a[3]   (*  out=  π  *)
    
  • KubaKuba finds it very useful for writing readable controllers definitions.

E.g.

    asso = <|"nested" -> <|"key" -> <|
        "spec" -> <|"a" -> 1, "b" ->  0|>
    |>|>|>;

    With[{
      a := asso["nested", "key", "spec", "a"],
      b := asso["nested", "key", "spec", "b"]
      },
     DynamicModule[{},
       Column@{
        Slider@Dynamic[a],
        Slider[Dynamic[b, {Automatic, (a = b^2) &}]],
        Dynamic@asso
        }
     ]
 
    ]

The earliest Stack Exchange usage of this that I can find is a post by Szabolcs.

I implemented a similar syntax in my listWith functionmy listWith function which is itself an extension of With.


Sequential With

From Daniel Lichtblau's comment there is a new undocumented syntax for With introduced sometime after version 10.1 that allows:

With[{a = 0}, {a = a + 1}, {a = a + 1}, a]
2

Delayed With, Block, and Module

These scoping constructs support the use of := in definitions which allows one to handle unevaluated expressions.

With[{x := 2 + 2}, Trace[x]]
Block[{x := 2 + 2}, Trace[x]]
Module[{x := 2 + 2}, Trace[x]]
{2 + 2, 4}
{x, 2 + 2, 4}
{x$6064, 2 + 2, 4}

###Examples:

  • I find this most useful in With since it inserts definitions into held expressions.
    I commonly use this for in-place modification of DownValues:

      a[1] = Pi;
      a[2] = E;
    
      With[{dv := DownValues[a]},  dv = dv /. {1 -> 3};]
    
       a[3]   (*  out=  π  *)
    
  • Kuba finds it very useful for writing readable controllers definitions.

E.g.

    asso = <|"nested" -> <|"key" -> <|
        "spec" -> <|"a" -> 1, "b" ->  0|>
    |>|>|>;

    With[{
      a := asso["nested", "key", "spec", "a"],
      b := asso["nested", "key", "spec", "b"]
      },
     DynamicModule[{},
       Column@{
        Slider@Dynamic[a],
        Slider[Dynamic[b, {Automatic, (a = b^2) &}]],
        Dynamic@asso
        }
     ]
 
    ]

The earliest Stack Exchange usage of this that I can find is a post by Szabolcs.

I implemented a similar syntax in my listWith function which is itself an extension of With.


Sequential With

From Daniel Lichtblau's comment there is a new undocumented syntax for With introduced sometime after version 10.1 that allows:

With[{a = 0}, {a = a + 1}, {a = a + 1}, a]
2

Delayed With, Block, and Module

These scoping constructs support the use of := in definitions which allows one to handle unevaluated expressions.

With[{x := 2 + 2}, Trace[x]]
Block[{x := 2 + 2}, Trace[x]]
Module[{x := 2 + 2}, Trace[x]]
{2 + 2, 4}
{x, 2 + 2, 4}
{x$6064, 2 + 2, 4}

###Examples:

  • I find this most useful in With since it inserts definitions into held expressions.
    I commonly use this for in-place modification of DownValues:

      a[1] = Pi;
      a[2] = E;
    
      With[{dv := DownValues[a]},  dv = dv /. {1 -> 3};]
    
       a[3]   (*  out=  π  *)
    
  • Kuba finds it very useful for writing readable controllers definitions.

E.g.

    asso = <|"nested" -> <|"key" -> <|
        "spec" -> <|"a" -> 1, "b" ->  0|>
    |>|>|>;

    With[{
      a := asso["nested", "key", "spec", "a"],
      b := asso["nested", "key", "spec", "b"]
      },
     DynamicModule[{},
       Column@{
        Slider@Dynamic[a],
        Slider[Dynamic[b, {Automatic, (a = b^2) &}]],
        Dynamic@asso
        }
     ]
 
    ]

The earliest Stack Exchange usage of this that I can find is a post by Szabolcs.

I implemented a similar syntax in my listWith function which is itself an extension of With.

added 618 characters in body
Source Link
Kuba
  • 139k
  • 13
  • 298
  • 810
 

Sequential With

From Daniel Lichtblau's comment there is a new undocumented syntax for With introduced sometime after version 10.1 that allows:

With[{a = 0}, {a = a + 1}, {a = a + 1}, a]
2
 

Delayed With, Block, and Module

These scoping constructs support the use of := in definitions which allows one to handle unevaluated expressions.

With[{x := 2 + 2}, Trace[x]]
Block[{x := 2 + 2}, Trace[x]]
Module[{x := 2 + 2}, Trace[x]]
{2 + 2, 4}
{x, 2 + 2, 4}
{x$6064, 2 + 2, 4}

I find this most useful in With since it inserts definitions into held expressions.
I commonly use this for in-place modification of DownValues###Examples:

  • I find this most useful in With since it inserts definitions into held expressions.
    I commonly use this for in-place modification of DownValues:

      a[1] = Pi;
      a[2] = E;
    
      With[{dv := DownValues[a]},  dv = dv /. {1 -> 3};]
    
       a[3]   (*  out=  π  *)
    
  • Kuba finds it very useful for writing readable controllers definitions.

E.g.

a[1]    asso = Pi;<|"nested" -> <|"key" -> <|
a[2] = E;      "spec" -> <|"a" -> 1, "b" ->  0|>
    |>|>|>;

    With[{dv
      a := DownValues[a]}asso["nested", "key", "spec", dv"a"],
      b := dvasso["nested", /."key", {1"spec", ->"b"]
 3     };],
     DynamicModule[{},
a[3]   (*  out=  πColumn@{
  *      Slider@Dynamic[a],
        Slider[Dynamic[b, {Automatic, (a = b^2) &}]],
        Dynamic@asso
        }
     ]
 
    ]

The earliest Stack Exchange usage of this that I can find is a post by Szabolcs.

I implemented a similar syntax in my listWith function which is itself an extension of With.

Sequential With

From Daniel Lichtblau's comment there is a new undocumented syntax for With introduced sometime after version 10.1 that allows:

With[{a = 0}, {a = a + 1}, {a = a + 1}, a]
2

Delayed With, Block, and Module

These scoping constructs support the use of := in definitions which allows one to handle unevaluated expressions.

With[{x := 2 + 2}, Trace[x]]
Block[{x := 2 + 2}, Trace[x]]
Module[{x := 2 + 2}, Trace[x]]
{2 + 2, 4}
{x, 2 + 2, 4}
{x$6064, 2 + 2, 4}

I find this most useful in With since it inserts definitions into held expressions.
I commonly use this for in-place modification of DownValues:

a[1] = Pi;
a[2] = E;

With[{dv := DownValues[a]},  dv = dv /. {1 -> 3};]

a[3]   (*  out=  π  *)

The earliest Stack Exchange usage of this that I can find is a post by Szabolcs.

I implemented a similar syntax in my listWith function which is itself an extension of With.

 

Sequential With

From Daniel Lichtblau's comment there is a new undocumented syntax for With introduced sometime after version 10.1 that allows:

With[{a = 0}, {a = a + 1}, {a = a + 1}, a]
2
 

Delayed With, Block, and Module

These scoping constructs support the use of := in definitions which allows one to handle unevaluated expressions.

With[{x := 2 + 2}, Trace[x]]
Block[{x := 2 + 2}, Trace[x]]
Module[{x := 2 + 2}, Trace[x]]
{2 + 2, 4}
{x, 2 + 2, 4}
{x$6064, 2 + 2, 4}

###Examples:

  • I find this most useful in With since it inserts definitions into held expressions.
    I commonly use this for in-place modification of DownValues:

      a[1] = Pi;
      a[2] = E;
    
      With[{dv := DownValues[a]},  dv = dv /. {1 -> 3};]
    
       a[3]   (*  out=  π  *)
    
  • Kuba finds it very useful for writing readable controllers definitions.

E.g.

    asso = <|"nested" -> <|"key" -> <|
        "spec" -> <|"a" -> 1, "b" ->  0|>
    |>|>|>;

    With[{
      a := asso["nested", "key", "spec", "a"],
      b := asso["nested", "key", "spec", "b"]
      },
     DynamicModule[{},
       Column@{
        Slider@Dynamic[a],
        Slider[Dynamic[b, {Automatic, (a = b^2) &}]],
        Dynamic@asso
        }
     ]
 
    ]

The earliest Stack Exchange usage of this that I can find is a post by Szabolcs.

I implemented a similar syntax in my listWith function which is itself an extension of With.

added 162 characters in body
Source Link
Mr.Wizard
  • 275.3k
  • 35
  • 608
  • 1.5k
Loading
added 299 characters in body
Source Link
Mr.Wizard
  • 275.3k
  • 35
  • 608
  • 1.5k
Loading
added 141 characters in body
Source Link
Mr.Wizard
  • 275.3k
  • 35
  • 608
  • 1.5k
Loading
added 383 characters in body
Source Link
Mr.Wizard
  • 275.3k
  • 35
  • 608
  • 1.5k
Loading
Source Link
Mr.Wizard
  • 275.3k
  • 35
  • 608
  • 1.5k
Loading
Post Made Community Wiki by Mr.Wizard