sofus_en.py

Created by alain-busser

Created on March 11, 2019

1.28 KB

Sofus is a programming language, inspired by Cobol, but object-programmed. It has variables, which have a value (a float), and can be inverted or raised by or lowered by or multiplied by or divided by or raised to the power, any constant increment/factor/power, or any other variable. Try for example

price = Variable(100) for n in range(100): price.raise_by(1,percents)


percents = "percents"
thesquare = 2
thecube = 3
def thepower(n): return n

class Variable():
    def __init__(self,v):
        self.value = float(v)
    def __str__(self):
        return str(self.value)
    def __repr__(self):
        return str(self.value)
    def raise_by(self,d=1,mode=None):
        if hasattr(d,'value'):
            d = d.value
        if mode == None:
            self.value += d
        elif mode == percents:
            self.value *= 1+d/100
    def lower_by(self,d=1,mode=None):
        if hasattr(d,'value'):
            d = d.value
        if mode == None:
            self.value -= d
        elif mode == percents:
            self.value *= 1-d/100
    def multiply_by(self,d=2,mode=None):
        if hasattr(d,'value'):
            d = d.value
        if mode == None:
            self.value *= d
        elif mode == percents:
            self.value *= d/100
    def divide_by(self,d=2,mode=None):
        if hasattr(d,'value'):
            d = d.value
        if mode == None:
            self.value /= d
        elif mode == percents:
            self.value /= d/100
    def raise_to(self,power=thesquare):
        if hasattr(power,'value'):
            power = power.value
        self.value **= power
    def invert(self):
        self.value = 1/self.value

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.