--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/ed901655-3494-44e7-af34-142cfb52e958n%40googlegroups.com.
I don't think you even need a c level debugger. You can see problems appear in your fields shown in the debugger before it crashes.I think the declaration of recomputed_cost as numeric causes the grief, because you are in a strange world where the code is using a reference where you intend to use an Integer.
I saw a huge number in a integer field which looked much like a pointer, and a Result that was void, when it should have been an integer.
I would get rid of the anchors everywhere and be more careful with which values are references and which are expanded. Remember there are Integer_refs.
This appears to be the case with this code. Generics mixed with more abstract types like NUMERIC was a nearly immediate code smell to me. So, the quickest way to test that theory was to change from NUMERIC to INTEGER and see if it compiled. It did. So, the next step was to run the program and see if the segfault persisted. It did not.
Moral of the story—you did the right thing by reaching out. I also find that I can get horse blinders on myself and it takes another person to spot my error or give me new ideas and approaches. My accounting professor in school called it Accountants Disease. When one looks at a column of numbers and cannot see the error in their addition any longer. :-)

On 20 Dec 2021, at 05:55, Jimmy Johnson <eiffe...@gmail.com> wrote:
I removed the self-initialization from `cost_imp' and redefined `default_create' to set the value. From WALK:default_create
-- Create an instance
do
cost_imp := recomputed_cost
endIf I step into this feature, it seems that `recomputed_cost' executes fine, returning INTEGER equal to zero. But the assignment forces a call to `twin' from INTEGER_32, for which the result is zero. But after the assignment the debugger shows:
<Screen Shot 2021-12-19 at 11.48.50 AM.png>At this point `cost_imp' is obviously wrong, and `my_cost', which was not even touched should be zero. So why is twin called? Back to the expanded versus reference type issue?jjj
--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/3b2ae0a7-dacd-4240-baa3-46e06bbe7407n%40googlegroups.com.
and complex number weights could of instance mimic electrical circuitry where impedances are complex.Simon
(above). Nevertheless—I am really intrigued by your findings! I wonder how Alex, Jocelyn and others at Eiffel Software would weigh in on the subject as you have presented it?
Also note: I further modified the WEIGHTED_PATH class with more C Generics, which seemed to make better sense given the overall design choices I am making.





Segfaults for me as well, but I do what the IDE says to do ... open the error and read it.
Looking further to see what "upper" says, and ...
Error on expression : "upper"
[VEEN] Error VEEN
Error code: VEEN
Error: unknown identifier.
What to do: make sure that identifier, if needed, is final name of
feature of class, or local entity or formal argument of routine.
Class: WALK
Feature: edge_count
Identifier: upper
Target type: [attached like Current] attached WALK
Line: 1
->note
description: "[So—the segmentation fault is that upper does not have an object--void target call/reference.
When you create type anchors, always make them detachable! Never use features that must be created (non-void).
The reason you're getting a segfault is that your code is reaching out to an uninitialized feature (edge_anchor) and trying get a type reference that is not there at the time of the call.
EXAMPLE:
- In WALK, the edge_anchor is now: edge_anchor: detachable EDGE- Also in WALK, the default_create now has two ensure then contracts:ensure then
has_edges: attached edges
edges_type: attached {LINKED_LIST [attached like edge_anchor]} edges- Also in WALK, edges is just:edges: LINKED_LIST [attached like edge_anchor]- Also in Walk, extend is now:extend (a_edge: attached like edge_anchor)- NOW—in WEIGHTED_PATH, edge_anchor is simply:edge_anchor: detachable WEIGHTED_EDGE [C]
Also note--if you want something that ensures edge_anchor is not accessed, then set it as an attribute with a ensure contract, such that:edge_anchor: detachable WEIGHTED_EDGE [C]-- Anchor for features using edges.
-- Not to be called; just used to anchor types.
-- Declared as a feature to avoid adding an attribute.
attribute
do_nothing
ensure then
do_not_call: False
end
Of course, you can put this on the feature in WALK instead and it will carry to inherited and redefinitions as well.MORAL OF THE STORY: Simply do not create type anchors that are anything other than detachable. If they are there for a non-useable type-reference, then so be it. Otherwise, before you access the type anchoring feature of a non-void target, you will need to do a creation of that target feature.
FINALLY--I run this code successfully now with no segfault.
Larry, thanks for digging into this. I'm still digesting what you wrote, but here are my off-the-cuff thoughts.
Now I have to explicitly say "attached" in every declaration? Seems like a lot of typing. Since the anchors never get called anyway, I don't understand the necessity for this.
But this adds an attribute to the class, even if Void, where a feature does not add an attribute. I used non-callable (I thought) features to prevent adding an attribute to the object.
...
Again. I don't see where I an "creating" any of the anchors.
Okay, I'm not convinced, but I am going to try your suggestion and see what I can get. I still think it has something to do with declaring `recomputed_cost' as NUMERIC and then redefining to be generic type C.Thanks again.jjj
But this adds an attribute to the class, even if Void, where a feature does not add an attribute. I used non-callable (I thought) features to prevent adding an attribute to the object....Again. I don't see where I an "creating" any of the anchors.
But this adds an attribute to the class, even if Void, where a feature does not add an attribute. I used non-callable (I thought) features to prevent adding an attribute to the object....Again. I don't see where I an "creating" any of the anchors.One other thing to say about this—I generally place such type anchor references in "feature {NONE} -- Implementation: Anchors" feature clauses so that they are not accessible or reference-
Finally—if you want to ensure that the detachable type anchor feature never actually gets attached then add a class invariant specifying this fact or reality (i.e. you want your program to break if a
Client ever actually tries to attach an object to your type anchor reference).
Now I have to explicitly say "attached" in every declaration? Seems like a lot of typing. Since the anchors never get called anyway, I don't understand the necessity for this.I know you are not kidding, but are you kidding? :-)
But this adds an attribute to the class, even if Void, where a feature does not add an attribute. I used non-callable (I thought) features to prevent adding an attribute to the object....
Again. I don't see where I an "creating" any of the anchors.You are not "creating" any anchors as features at all (i.e. for calling by a caller). They are type references. They only need to be there for the compiler at compile-time. Because of dead-code removal, I am not even sure if they exist in the finalized EXE at all. Now, as a type reference they might exist in the EXE, but (again) they are just references for those features that require a type reference. They perform no other useful function in your program.
Yes—you do need to type attached like for each instance where you actually utilize the type reference (anchor). This is not unreasonable and it is not a lot of typing. As Bertrand wrote years ago—there is no tax on keystrokes. But—if it makes you feel better—if the point in code where you need to reference the type anchor reference does not need to be attached (non-void), then you do not need to type the keyword attached. Why? Because when you write like that liking-reference
Remember—the way you had the code, you were creating a feature that was non-void (attached) and (therefore) you were responsible for creating it at creation time in a creation procedure—or—making it as a self-creating attribute. The segfault error was arising because when your code arrived at the point where it was referencing your type anchor, the object was not created and was
therefore NULL (Void). Because there was no object to reference and fetch its type, the program failed with a call on void target segfault. Had the object actually been created, there would have been an object to reference and (therefore) a type reference to successfully fetch and utilize in a like.
Moreover—the reason your program did not fail in the debugger as you stepped through is because (I think) the debugger provides extra data about the program for debugging purposes as it executes. That data is not present in the W-Code or F-Code version of an EXE—only in the Debugger-Code version. So, in either W-Code or F-Code EXE, the object was not there, so the Void-target call failed as a segfault.
Again—the way out of that trap is two-fold. Either ...
1. Ensure that the object is created BEFORE it is referenced.
2. Ensure that the type anchor is detachable and that if the referencing like is attached then ensure you use the attached keyword in that reference.Finally—if you use the format of declaring type references as detachable then you do not have to worry about them being called as such. Why? because there is nothing there to call, only to reference (which is their purpose, yes?). This means you do not need to put in code as a guard dog over the type reference feature. As a programmer, even the IDE + Compiler will stop you from calling the feature as though it were callable (executable). It is not. It is a void-object reference only. Nothing to see here. Move along.
On 30 Dec 2021, at 10:39, lrix <lr...@jinny.com> wrote:
Jimmy—do you still have my phone number? Perhaps a voice call would help because we're way far in the weeds and it seems obvious that something is being misunderstood by one or both of us. I just want to ensure I understand you clearly and I don't think I am.
--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/55b95b09-c5e3-4218-90f5-b5084144028en%40googlegroups.com.
classEDGE [C -> {NUMERIC} create default_create end]feature -- Accesscost: C-- Cost for traversing `Current'.doResult := (create {C}).oneendend
--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/086280fe-1650-4879-9147-462f1cf6c1b1n%40googlegroups.com.
Hi LarryThat's a good way to get it to work but I worry that there remains an underlying problem.The 'like' mechanism should be associating a type (i.e. a class), NOT an instance. The anchor feature is never called, EVER, in the program definition (i.e. the code). Ass such, it should never be called by another entity i.e. the runtime system).
I worry that the type anchoring, that SHOULD occur at compile time is somehow off (it should not have to look at the anchor feature at runtime), perhaps the victim of dead code removal.
Eiffel has static typing and so this problem should never occur, and yet it does.That said, it should be permitted to do exactly as you describe. That method makes the code more explicit, but I think it also makes is unnecessarily wordy. The anchor feature
exists once in the code, but (presumably, else why use an anchor) its type affiliations (instances of 'like') are possibly many.R
Jimmy.Also—I changed nothing about your design,. That is your choice to make. All I did was comment out the require ... do ... end on your type-anchors (edge_anchor) and make them detachable. I then located the references (a pair of arguments) and made them attached like instead of just like.
The problem is always the same. You get a segfault because at run-time the code tries to type-ref a Void feature. By making the type-anchoring feature detachable and using the attached like on the references, you get what you want—working code.
LOL—is everyone just missing the point?
- The very definition of a type anchor is the type and not an attached object. Making detachable signifies that. Giving it a do ... end routine body is silliness because, as you said, nobody is going to CALL it. All they will do is reference it.
- Even using an attribute ... end to provide a lazy-instance of an object is also a little silly when all one wants is the type, anchored to a feature.
- Wordy? Seriously? I am falling into the looking glass. Is it seriously difficult to type the word attached or even to read it? We cannot be having this discussion, right?
- To your credit, I think what you are really griping about here is a nuance in the compiler's static type checking vs run-time object reference behavior.
Thoughts about that last pointI think what you expect is for the compiler to statically use the anchor type definition. HOWEVER—once you make that a non-Void type in a run-time situation, here is what you are left with: You are left with a POLYMORPHIC OBJECT that can be whatever type you declared AND any valid legal polymorphic descendent type. THEREFORE—you MUST have an object for the run-time program to reference through the like in wherever it is being referenced!
Compare that to having a detachable type anchor.In the detachable version, the type reference will NOT be based on the type of the OBJECT pointed to by the feature. It will simply be as you are expecting—a reference based on the type of the anchor feature declared statically just as you read it in the code.
The ONE nuance will be IF you redefine the type-anchor reference in a descendant class. If you do—NO PROBLEM! The compiler is quite good at understanding your polymorphic construction and changes the expectation in the like reference based on the descendant class anchor reference.
Again—putting a feature that MUST have an attached object means you THROW AWAY the static type reference of the code and change the reference to an OBJECT INSTANCE AT RUN-TIME because of polymorphic assignment capacity on that feature. It doesn't matter if it is ever "called" or not.
Sunday, January 16, 2022 7:46 PM +03:00 from Jimmy Johnson <eiffe...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/d4ad6674-1c17-41ae-90c6-00bc949a874an%40googlegroups.com.