Skip to main content
added 3 characters in body
Source Link
user13892
  • 9.8k
  • 2
  • 15
  • 44

Consider the following functional as an example:

ClearAll[urlModifier];
urlModifier[url_]:=ReplaceAll[Function@Evaluate[
    Inactive[URLBuild][
        URLParse[url]/.{"slot"->Inactive[StringReplace][Slot[]," "->"_"]}
    ]
],{Inactive[x_]:>x}];

If I evaluate it using the following command:

urlModifier["https://www.somewebsite.com/path/slot"]["hello world!"]

It fails probably because the Slot[] is not aligning with the Function.

But if I do in-place evaluation of urlModifier["https://www.somewebsite.com/path/slot"] and use the result as input:

URLBuild[<|"Scheme"->"https","User"->None,"Domain"->"www.somewebsite.com","Port"->None,"Path"->{"","path",StringReplace[Slot[]," "->"_"]},"Query"->{},"Fragment"->None|>]&["hello world!"]

It works fine.

What should I do to urlModifier to make it accept the Slot[] for its Function that it creates?

Consider the following functional as an example:

ClearAll[urlModifier];
urlModifier[url_]:=ReplaceAll[Function@Evaluate[
    Inactive[URLBuild][
        URLParse[url]/.{"slot"->Inactive[StringReplace][Slot[]," "->"_"]}
    ]
],{Inactive[x_]:>x}];

If I evaluate it using the following command:

urlModifier["https://www.somewebsite.com/path/slot"]["hello world!"]

It fails probably because the Slot[] is not aligning with the Function.

But if I do in-place evaluation of urlModifier["https://www.somewebsite.com/path/slot"] and use the result as input:

URLBuild[<|"Scheme"->"https","User"->None,"Domain"->"www.somewebsite.com","Port"->None,"Path"->{"","path",StringReplace[Slot[]," "->"_"]},"Query"->{},"Fragment"->None|>]&["hello world!"]

It works fine.

What should I do to urlModifier to make accept the Slot[] for its Function that it creates?

Consider the following functional as an example:

ClearAll[urlModifier];
urlModifier[url_]:=ReplaceAll[Function@Evaluate[
    Inactive[URLBuild][
        URLParse[url]/.{"slot"->Inactive[StringReplace][Slot[]," "->"_"]}
    ]
],{Inactive[x_]:>x}];

If I evaluate it using the following command:

urlModifier["https://www.somewebsite.com/path/slot"]["hello world!"]

It fails probably because the Slot[] is not aligning with the Function.

But if I do in-place evaluation of urlModifier["https://www.somewebsite.com/path/slot"] and use the result as input:

URLBuild[<|"Scheme"->"https","User"->None,"Domain"->"www.somewebsite.com","Port"->None,"Path"->{"","path",StringReplace[Slot[]," "->"_"]},"Query"->{},"Fragment"->None|>]&["hello world!"]

It works fine.

What should I do to urlModifier to make it accept the Slot[] for its Function that it creates?

edited tags
Link
Became Hot Network Question
Tweeted twitter.com/StackMma/status/1157486494568931331
edited title
Source Link
user13892
  • 9.8k
  • 2
  • 15
  • 44

How to define a functionfunctional that produces at runtime a function by evaluating particularselected parts in its definition?

Consider the following functionfunctional as an example:

ClearAll[urlModifier];
urlModifier[url_]:=ReplaceAll[Function@Evaluate[
    Inactive[URLBuild][
        URLParse[url]/.{"slot"->Inactive[StringReplace][Slot[]," "->"_"]}
    ]
],{Inactive[x_]:>x}];

If I evaluate it using the following command:

urlModifier["https://www.somewebsite.com/path/slot"]["hello world!"]

It fails probably because the Slot[] is not aligning with the Function.

But if I do in-place evaluation of urlModifier["https://www.somewebsite.com/path/slot"] and use the result as input:

URLBuild[<|"Scheme"->"https","User"->None,"Domain"->"www.somewebsite.com","Port"->None,"Path"->{"","path",StringReplace[Slot[]," "->"_"]},"Query"->{},"Fragment"->None|>]&["hello world!"]

It works fine.

What should I do to urlModifier to make accept the Slot[] for its Function that it creates?

How to define a function at runtime by evaluating particular parts in definition?

Consider the following function as an example:

ClearAll[urlModifier];
urlModifier[url_]:=ReplaceAll[Function@Evaluate[
    Inactive[URLBuild][
        URLParse[url]/.{"slot"->Inactive[StringReplace][Slot[]," "->"_"]}
    ]
],{Inactive[x_]:>x}];

If I evaluate it using the following command:

urlModifier["https://www.somewebsite.com/path/slot"]["hello world!"]

It fails probably because the Slot[] is not aligning with the Function.

But if I do in-place evaluation of urlModifier["https://www.somewebsite.com/path/slot"] and use the result as input:

URLBuild[<|"Scheme"->"https","User"->None,"Domain"->"www.somewebsite.com","Port"->None,"Path"->{"","path",StringReplace[Slot[]," "->"_"]},"Query"->{},"Fragment"->None|>]&["hello world!"]

It works fine.

What should I do to urlModifier to make accept the Slot[] for its Function that it creates?

How to define a functional that produces at runtime a function by evaluating selected parts in its definition?

Consider the following functional as an example:

ClearAll[urlModifier];
urlModifier[url_]:=ReplaceAll[Function@Evaluate[
    Inactive[URLBuild][
        URLParse[url]/.{"slot"->Inactive[StringReplace][Slot[]," "->"_"]}
    ]
],{Inactive[x_]:>x}];

If I evaluate it using the following command:

urlModifier["https://www.somewebsite.com/path/slot"]["hello world!"]

It fails probably because the Slot[] is not aligning with the Function.

But if I do in-place evaluation of urlModifier["https://www.somewebsite.com/path/slot"] and use the result as input:

URLBuild[<|"Scheme"->"https","User"->None,"Domain"->"www.somewebsite.com","Port"->None,"Path"->{"","path",StringReplace[Slot[]," "->"_"]},"Query"->{},"Fragment"->None|>]&["hello world!"]

It works fine.

What should I do to urlModifier to make accept the Slot[] for its Function that it creates?

Source Link
user13892
  • 9.8k
  • 2
  • 15
  • 44
Loading