AREPL-vscode icon indicating copy to clipboard operation
AREPL-vscode copied to clipboard

How can I use #$save partly?

Open tkxkd0159 opened this issue 5 years ago • 7 comments
trafficstars

Thank you for giving me a nice extension but I have a question about how to apply #$save in part of whole codes like below:

import Calculate
result1 = Calculate.diff(something)
result2 = Calculate.add(something)

# I want to start save from here

def largest_prime_factor(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
    return n

def another_heavy_function(n):
    some_heavy_processing
    return heavy_res

result_big = largest_prime_factor(8008514751439999)
result_big2 = another_heavy(13123213123)

# I want to stop save from here

other_excute_after_save = Calculate.sum(something)
other_excute_after_save = Calculate.partial(something) 
print("code end line")

I am so sorry if you have already guided it in your doc. but I can't find. I can only see the case that stores from the start of codes to the #$save line

tkxkd0159 avatar Feb 09 '20 09:02 tkxkd0159

I would use the special arepl_store variable so you can store the result of largest_prime_factor while still getting the real-time execution. You can find the docs here. But unfortunately I just found out arepl_store is broken 🙈

I'll see if I can fix it. In the meantime I would try using #$end. I use #$end more than #$save anyways because #$save can be buggy.

https://github.com/Almenon/AREPL-vscode#end

import Calculate
something = 5
result1 = Calculate.diff(something)
result2 = Calculate.add(something)

#$end

# use control-enter to evaluate blocks of code
# if you change something in Calculator add a space or something before #$end so arepl runs and it gets re-imported

def largest_prime_factor(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
    return n

result_big = largest_prime_factor(8002001234567)

other_excute_after_save = Calculate.sum(something)
other_excute_after_save = Calculate.partial(something) 
print("code end line")

Almenon avatar Feb 09 '20 17:02 Almenon

Thank you for your guidance! if so, can I exclude only some sections in the whole code? like below:

import pkg1
import pkg2

print("start point of low-cost code")
...
...
print("end point of low-cost code")

#$end
# I want to end of real-time code here
print("start point of high-cost code")
...
...
print("endpoint of high-cost code")


# I want to restart of real-time code here

print("another start point of low-cost code")
...
...
print("endpoint of low-cost code")

tkxkd0159 avatar Feb 09 '20 17:02 tkxkd0159

Unfortunately not. Each time a real-time arepl run is triggered it starts off from a fresh start, so in your scenario any variables in #$end would be wiped the next real-time run and as such would not be usable in the restart of the real-time code section.

One thing I could do is add a setting for idempotency. If toggled off the arepl run would use prexisting variables rather than starting from scratch. Basically it would give the whole file the idempotency of the #$end block. This would be a very easy setting to add.

Almenon avatar Feb 13 '20 06:02 Almenon

I fixed arepl_store in the backend, it should work next release.

Almenon avatar Feb 22 '20 17:02 Almenon

I just released v1.0.21, arepl_store should work now :)

Almenon avatar Feb 23 '20 04:02 Almenon

Next release will have a setting for idempotency

Almenon avatar Feb 27 '20 05:02 Almenon

I just released 1.0.22. It has a setting for idempotency called keepPreviousVars. If set to true AREPL will add onto the local state each run instead of clearing it and starting from fresh. This will let you write high-cost code that initializes a variable, comment out the high-cost code, but still have the variable to play around with :)

Almenon avatar Mar 22 '20 18:03 Almenon