What is wrong with Module? or me?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












The following code does not give me an answer. It looks all is working when each command inside Module is individually run. But as a Module, it does not.



Can you tell me what is wrong with my formulation?



SeedRandom[02];

Gr = RandomGraph[6, 10, DirectedEdges -> True, VertexLabels -> "Name"];

sourceANDsinkF[G_, s_, t_] := Module[e, source, sink,
e = DeleteDuplicates[EdgeList[G]];
source = Cases[e, s [DirectedEdge] _];
sink = Cases[e, _ [DirectedEdge] t]];









share|improve this question























  • How do you call the function you have defined?
    – mikado
    1 hour ago











  • did you call the function? sourceANDsinkF[Gr,1,2] ??
    – Ali Hashmi
    59 mins ago











  • @Mikado and @AliH: I call the function as sourceANDsinkF[Gr, 1, 2] for example.
    – Tugrul Temel
    56 mins ago














up vote
1
down vote

favorite












The following code does not give me an answer. It looks all is working when each command inside Module is individually run. But as a Module, it does not.



Can you tell me what is wrong with my formulation?



SeedRandom[02];

Gr = RandomGraph[6, 10, DirectedEdges -> True, VertexLabels -> "Name"];

sourceANDsinkF[G_, s_, t_] := Module[e, source, sink,
e = DeleteDuplicates[EdgeList[G]];
source = Cases[e, s [DirectedEdge] _];
sink = Cases[e, _ [DirectedEdge] t]];









share|improve this question























  • How do you call the function you have defined?
    – mikado
    1 hour ago











  • did you call the function? sourceANDsinkF[Gr,1,2] ??
    – Ali Hashmi
    59 mins ago











  • @Mikado and @AliH: I call the function as sourceANDsinkF[Gr, 1, 2] for example.
    – Tugrul Temel
    56 mins ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











The following code does not give me an answer. It looks all is working when each command inside Module is individually run. But as a Module, it does not.



Can you tell me what is wrong with my formulation?



SeedRandom[02];

Gr = RandomGraph[6, 10, DirectedEdges -> True, VertexLabels -> "Name"];

sourceANDsinkF[G_, s_, t_] := Module[e, source, sink,
e = DeleteDuplicates[EdgeList[G]];
source = Cases[e, s [DirectedEdge] _];
sink = Cases[e, _ [DirectedEdge] t]];









share|improve this question















The following code does not give me an answer. It looks all is working when each command inside Module is individually run. But as a Module, it does not.



Can you tell me what is wrong with my formulation?



SeedRandom[02];

Gr = RandomGraph[6, 10, DirectedEdges -> True, VertexLabels -> "Name"];

sourceANDsinkF[G_, s_, t_] := Module[e, source, sink,
e = DeleteDuplicates[EdgeList[G]];
source = Cases[e, s [DirectedEdge] _];
sink = Cases[e, _ [DirectedEdge] t]];






programming scoping






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 48 mins ago









J. M. is somewhat okay.♦

94.5k10293454




94.5k10293454










asked 1 hour ago









Tugrul Temel

35811




35811











  • How do you call the function you have defined?
    – mikado
    1 hour ago











  • did you call the function? sourceANDsinkF[Gr,1,2] ??
    – Ali Hashmi
    59 mins ago











  • @Mikado and @AliH: I call the function as sourceANDsinkF[Gr, 1, 2] for example.
    – Tugrul Temel
    56 mins ago
















  • How do you call the function you have defined?
    – mikado
    1 hour ago











  • did you call the function? sourceANDsinkF[Gr,1,2] ??
    – Ali Hashmi
    59 mins ago











  • @Mikado and @AliH: I call the function as sourceANDsinkF[Gr, 1, 2] for example.
    – Tugrul Temel
    56 mins ago















How do you call the function you have defined?
– mikado
1 hour ago





How do you call the function you have defined?
– mikado
1 hour ago













did you call the function? sourceANDsinkF[Gr,1,2] ??
– Ali Hashmi
59 mins ago





did you call the function? sourceANDsinkF[Gr,1,2] ??
– Ali Hashmi
59 mins ago













@Mikado and @AliH: I call the function as sourceANDsinkF[Gr, 1, 2] for example.
– Tugrul Temel
56 mins ago




@Mikado and @AliH: I call the function as sourceANDsinkF[Gr, 1, 2] for example.
– Tugrul Temel
56 mins ago










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










What do you want to see?



without the module:



SeedRandom[02];
Gr = RandomGraph[6, 10, DirectedEdges -> True, VertexLabels -> "Name"]


enter image description here



e = DeleteDuplicates[EdgeList[Gr]]


enter image description here



source = Cases[e, 1 [DirectedEdge] _]
1 [DirectedEdge] 2, 1 [DirectedEdge] 5

sink = Cases[e, _ [DirectedEdge] 2]
1 [DirectedEdge] 2, 3 [DirectedEdge] 2


with the module



sourceANDsinkF[G_, s_, t_] := 
Module[e, source, sink, e = DeleteDuplicates[EdgeList[G]];
source = Cases[e, s [DirectedEdge] _];
sink = Cases[e, _ [DirectedEdge] t]];

sourceANDsinkF[Gr, 1, 2]
1 [DirectedEdge] 2, 3 [DirectedEdge] 2


or



sourceANDsinkF[G_, s_, t_] := 
Module[e, source, sink, e = DeleteDuplicates[EdgeList[G]];
source = Cases[e, s [DirectedEdge] _];
sink = Cases[e, _ [DirectedEdge] t];
source, sink];

sourceANDsinkF[Gr, 1, 2]


enter image description here






share|improve this answer




















  • Dear All, I am really surprised that none of the proposals above are working in my version of Mathematica 10, although you all show that my formulation should also work fine. I really do not know what else I can do. Any idea?
    – Tugrul Temel
    14 mins ago










  • My goal is: given Gr, I want to find all outgoing edges from source vertex and calculate the sum of the associated edge weights, and do the same for the sink vertex.
    – Tugrul Temel
    6 mins ago










  • Too bad, maybe an update to version 12 is possible? I did the calculations with version 11.3. Unfortunately, I can not help technically, is not my field of expertise.
    – rmw
    2 mins ago

















up vote
2
down vote













Remove the ";" at the end of Module[...], and it should work.enter image description here






share|improve this answer




















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183755%2fwhat-is-wrong-with-module-or-me%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    What do you want to see?



    without the module:



    SeedRandom[02];
    Gr = RandomGraph[6, 10, DirectedEdges -> True, VertexLabels -> "Name"]


    enter image description here



    e = DeleteDuplicates[EdgeList[Gr]]


    enter image description here



    source = Cases[e, 1 [DirectedEdge] _]
    1 [DirectedEdge] 2, 1 [DirectedEdge] 5

    sink = Cases[e, _ [DirectedEdge] 2]
    1 [DirectedEdge] 2, 3 [DirectedEdge] 2


    with the module



    sourceANDsinkF[G_, s_, t_] := 
    Module[e, source, sink, e = DeleteDuplicates[EdgeList[G]];
    source = Cases[e, s [DirectedEdge] _];
    sink = Cases[e, _ [DirectedEdge] t]];

    sourceANDsinkF[Gr, 1, 2]
    1 [DirectedEdge] 2, 3 [DirectedEdge] 2


    or



    sourceANDsinkF[G_, s_, t_] := 
    Module[e, source, sink, e = DeleteDuplicates[EdgeList[G]];
    source = Cases[e, s [DirectedEdge] _];
    sink = Cases[e, _ [DirectedEdge] t];
    source, sink];

    sourceANDsinkF[Gr, 1, 2]


    enter image description here






    share|improve this answer




















    • Dear All, I am really surprised that none of the proposals above are working in my version of Mathematica 10, although you all show that my formulation should also work fine. I really do not know what else I can do. Any idea?
      – Tugrul Temel
      14 mins ago










    • My goal is: given Gr, I want to find all outgoing edges from source vertex and calculate the sum of the associated edge weights, and do the same for the sink vertex.
      – Tugrul Temel
      6 mins ago










    • Too bad, maybe an update to version 12 is possible? I did the calculations with version 11.3. Unfortunately, I can not help technically, is not my field of expertise.
      – rmw
      2 mins ago














    up vote
    1
    down vote



    accepted










    What do you want to see?



    without the module:



    SeedRandom[02];
    Gr = RandomGraph[6, 10, DirectedEdges -> True, VertexLabels -> "Name"]


    enter image description here



    e = DeleteDuplicates[EdgeList[Gr]]


    enter image description here



    source = Cases[e, 1 [DirectedEdge] _]
    1 [DirectedEdge] 2, 1 [DirectedEdge] 5

    sink = Cases[e, _ [DirectedEdge] 2]
    1 [DirectedEdge] 2, 3 [DirectedEdge] 2


    with the module



    sourceANDsinkF[G_, s_, t_] := 
    Module[e, source, sink, e = DeleteDuplicates[EdgeList[G]];
    source = Cases[e, s [DirectedEdge] _];
    sink = Cases[e, _ [DirectedEdge] t]];

    sourceANDsinkF[Gr, 1, 2]
    1 [DirectedEdge] 2, 3 [DirectedEdge] 2


    or



    sourceANDsinkF[G_, s_, t_] := 
    Module[e, source, sink, e = DeleteDuplicates[EdgeList[G]];
    source = Cases[e, s [DirectedEdge] _];
    sink = Cases[e, _ [DirectedEdge] t];
    source, sink];

    sourceANDsinkF[Gr, 1, 2]


    enter image description here






    share|improve this answer




















    • Dear All, I am really surprised that none of the proposals above are working in my version of Mathematica 10, although you all show that my formulation should also work fine. I really do not know what else I can do. Any idea?
      – Tugrul Temel
      14 mins ago










    • My goal is: given Gr, I want to find all outgoing edges from source vertex and calculate the sum of the associated edge weights, and do the same for the sink vertex.
      – Tugrul Temel
      6 mins ago










    • Too bad, maybe an update to version 12 is possible? I did the calculations with version 11.3. Unfortunately, I can not help technically, is not my field of expertise.
      – rmw
      2 mins ago












    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    What do you want to see?



    without the module:



    SeedRandom[02];
    Gr = RandomGraph[6, 10, DirectedEdges -> True, VertexLabels -> "Name"]


    enter image description here



    e = DeleteDuplicates[EdgeList[Gr]]


    enter image description here



    source = Cases[e, 1 [DirectedEdge] _]
    1 [DirectedEdge] 2, 1 [DirectedEdge] 5

    sink = Cases[e, _ [DirectedEdge] 2]
    1 [DirectedEdge] 2, 3 [DirectedEdge] 2


    with the module



    sourceANDsinkF[G_, s_, t_] := 
    Module[e, source, sink, e = DeleteDuplicates[EdgeList[G]];
    source = Cases[e, s [DirectedEdge] _];
    sink = Cases[e, _ [DirectedEdge] t]];

    sourceANDsinkF[Gr, 1, 2]
    1 [DirectedEdge] 2, 3 [DirectedEdge] 2


    or



    sourceANDsinkF[G_, s_, t_] := 
    Module[e, source, sink, e = DeleteDuplicates[EdgeList[G]];
    source = Cases[e, s [DirectedEdge] _];
    sink = Cases[e, _ [DirectedEdge] t];
    source, sink];

    sourceANDsinkF[Gr, 1, 2]


    enter image description here






    share|improve this answer












    What do you want to see?



    without the module:



    SeedRandom[02];
    Gr = RandomGraph[6, 10, DirectedEdges -> True, VertexLabels -> "Name"]


    enter image description here



    e = DeleteDuplicates[EdgeList[Gr]]


    enter image description here



    source = Cases[e, 1 [DirectedEdge] _]
    1 [DirectedEdge] 2, 1 [DirectedEdge] 5

    sink = Cases[e, _ [DirectedEdge] 2]
    1 [DirectedEdge] 2, 3 [DirectedEdge] 2


    with the module



    sourceANDsinkF[G_, s_, t_] := 
    Module[e, source, sink, e = DeleteDuplicates[EdgeList[G]];
    source = Cases[e, s [DirectedEdge] _];
    sink = Cases[e, _ [DirectedEdge] t]];

    sourceANDsinkF[Gr, 1, 2]
    1 [DirectedEdge] 2, 3 [DirectedEdge] 2


    or



    sourceANDsinkF[G_, s_, t_] := 
    Module[e, source, sink, e = DeleteDuplicates[EdgeList[G]];
    source = Cases[e, s [DirectedEdge] _];
    sink = Cases[e, _ [DirectedEdge] t];
    source, sink];

    sourceANDsinkF[Gr, 1, 2]


    enter image description here







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 26 mins ago









    rmw

    2196




    2196











    • Dear All, I am really surprised that none of the proposals above are working in my version of Mathematica 10, although you all show that my formulation should also work fine. I really do not know what else I can do. Any idea?
      – Tugrul Temel
      14 mins ago










    • My goal is: given Gr, I want to find all outgoing edges from source vertex and calculate the sum of the associated edge weights, and do the same for the sink vertex.
      – Tugrul Temel
      6 mins ago










    • Too bad, maybe an update to version 12 is possible? I did the calculations with version 11.3. Unfortunately, I can not help technically, is not my field of expertise.
      – rmw
      2 mins ago
















    • Dear All, I am really surprised that none of the proposals above are working in my version of Mathematica 10, although you all show that my formulation should also work fine. I really do not know what else I can do. Any idea?
      – Tugrul Temel
      14 mins ago










    • My goal is: given Gr, I want to find all outgoing edges from source vertex and calculate the sum of the associated edge weights, and do the same for the sink vertex.
      – Tugrul Temel
      6 mins ago










    • Too bad, maybe an update to version 12 is possible? I did the calculations with version 11.3. Unfortunately, I can not help technically, is not my field of expertise.
      – rmw
      2 mins ago















    Dear All, I am really surprised that none of the proposals above are working in my version of Mathematica 10, although you all show that my formulation should also work fine. I really do not know what else I can do. Any idea?
    – Tugrul Temel
    14 mins ago




    Dear All, I am really surprised that none of the proposals above are working in my version of Mathematica 10, although you all show that my formulation should also work fine. I really do not know what else I can do. Any idea?
    – Tugrul Temel
    14 mins ago












    My goal is: given Gr, I want to find all outgoing edges from source vertex and calculate the sum of the associated edge weights, and do the same for the sink vertex.
    – Tugrul Temel
    6 mins ago




    My goal is: given Gr, I want to find all outgoing edges from source vertex and calculate the sum of the associated edge weights, and do the same for the sink vertex.
    – Tugrul Temel
    6 mins ago












    Too bad, maybe an update to version 12 is possible? I did the calculations with version 11.3. Unfortunately, I can not help technically, is not my field of expertise.
    – rmw
    2 mins ago




    Too bad, maybe an update to version 12 is possible? I did the calculations with version 11.3. Unfortunately, I can not help technically, is not my field of expertise.
    – rmw
    2 mins ago










    up vote
    2
    down vote













    Remove the ";" at the end of Module[...], and it should work.enter image description here






    share|improve this answer
























      up vote
      2
      down vote













      Remove the ";" at the end of Module[...], and it should work.enter image description here






      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        Remove the ";" at the end of Module[...], and it should work.enter image description here






        share|improve this answer












        Remove the ";" at the end of Module[...], and it should work.enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 29 mins ago









        t-smart

        830114




        830114



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183755%2fwhat-is-wrong-with-module-or-me%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery