convert string to list in Standard ML [duplicate] - programming-languages

This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
Open file in ML(SMLNJ)
I have a string value which has value like this:
"[(1,2,3),(2,3),(6,8)]" -> string
but I want to have these values in int type like this:
[(1,2,3),(2,3),(6,8)] -> (int list) list
what should I do?is there any function which can help me? or I have to do it myself?

This problem is perfectly suited to parsing combinators, which you can steal from my friend Greg Morrisett at Harvard.
If you want to understand the underlying ideas, read Graham Hutton's paper Higher-Order Functions for Parsing. If you want to know how to implement I/O in Standard ML, consult the TextIO module in the Standard Basis Library. If you want someone to write the code for you, you may have reached the wrong web site.

You can use stringint from the String module.
See for example http://wwwcgi.rdg.ac.uk:8081/cgi-bin/cgiwrap/wsi14/poplog/ml/help/string#Character%20Transformation%20Functions

Related

PySCIPOpt/SCIP - Branching/Separation with fractional variable

I began using PySCIPOpt/SCIP for a Coursera course on discrete optimization. I'd need to implement a simple separation from a fractional variable and wonder how to do it. Online SCIP literature does not provide relevant example.
Any Python example for me to get inspired for my assignment?
Thank you for the answer. Indeed I spent some hours reading SCIP documentation and I have trouble interfacing SCIp methods in Python.
I have been able to implement in Python a simple constraint handler to add first-type cuts and I'd like to add a separator to add second-type cuts.
The latter cuts are typically x = 0 or 1 cuts based on fractional x values and I stumble more with syntax - addCut() - and using generic methods than the process itself.
A Python example, a bit more involved than tsp.py, would greatly help me.
Your question is quite broad. I try to give some hints on where to look for an answer:
general information on separators in SCIP
difference between constraint handlers and separators
Python example on a separator implemented as constraint handler to solve the Traveling Salesman Problem
I can try to answer your question more precisely, if you explain your application/problem in more detail.

Swift: Compute equation within String and convert to Int [duplicate]

This question already has answers here:
NSExpression custom variables inside expression
(1 answer)
Swift - Resolving a math operation in a string
(4 answers)
Closed 7 years ago.
I have been wondering for far too long now: Is it possible in any way to convert a String containing an equation to Int?
For example, this is what I tried:
var equation: String? = "\(5) \(+) \(8)" // 5, +, and 8 would be generated Ints/operaters
if let answer = Int(equation) {
print("\(answer)")
}
I've been trying to find a way to do this across various languages with no luck. Any help is appreciated.
You're looking for an arithmetic expression evaluator, which isn't trivial to do and there doesn't exist a simple function that just does it. You can try to find an open-source implementation of a simple one.
EDIT: Have a look at the Arithmetic Evaluation Rosetta Code page, which is the simplest thing you probably want. There isn't a Swift version (yet), but you should be able to do it yourself by looking at the other languages.
Another EDIT: Check out this Code Golf Thread which features some of the shortest arithmetic expression evaluators in some languages (no Swift yet)
Last EDIT: Also have a look at the Shunting-yard algorithm and generalised Operator-precedence parsing. I'm actually very attempted now to write a simple one in Swift...
Post last EDIT: There exists a Swift library for that :D. Also: Downvotes are for non-useful answers (see hover text), not for when there's a better answer (see comments)

Constant values in Rust generics [duplicate]

This question already has answers here:
Is it possible to control the size of an array using the type parameter of a generic?
(2 answers)
Closed 2 years ago.
Does Rust language support constant values in generic code similar to c++ way? Seems that the language overview doesn't advertise it. Parameterizing types with constants in C++ allows to create objects with preallocated buffers of different size depending on client's needs (types like stlsoft::auto_buffer).
If not, then what is the best practices to implement similar designs in Rust?
No, this is not supported in a type-safe way. We would need type-level numeric literals, like GHC recently added, for that.
However, you can use Rust macros. With a macro you can create "templates" that are parameterized over arbitrary expressions, including constants, which would allow you to do what you want here. Note that you may find bugs and limitations in the macro system if you try this at the moment.

recursion - all permuations of a string [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Are there any better methods to do permutation of string?
I know recursion and can write programs like fibonacci number, tree traversals so I think I know it but when it comes to this question specifically I feel bad
Please guide me with how to calculate all possible permutations of a string
Here is good examples of different permutation algorithms, including recursive one: http://www.bearcave.com/random_hacks/permute.html

Why are strings called "strings"? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
The History Behind the Definition of a 'String'
About the only thing every programming language I've seen is able to agree upon is that a variable that refers to a block of text is called a "string." Why? Where does the name come from, and how did it become idiomatic across programming in general?
Great question! This might be somewhat helpful:
Strings are called "strings" because they are made up of a sequence, or string, of characters.
Source: http://www.vias.org/cppcourse/chap07_03.html
Very interesting,
The very definition of a string (according to Princeton at least) is:
a linear sequence of symbols
So, since the String datatype is a sequence of characters/symbols, it rather fits the definition.

Resources